W
W
Wolf_Yout2021-08-10 00:37:59
Python
Wolf_Yout, 2021-08-10 00:37:59

How to create multiple Discord.py commands?

Hi all. i'm new to python and i don't understand how to make some commands to my bot:

import discord
import asyncio
from asyncio import sleep

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_ready():
     while True:
          await client.change_presence(status=discord.Status.online, activity=discord.Game("$help"))
          await sleep(5)
          await client.change_presence(status=discord.Status.online,activity=discord.Game(f'{len(client.guilds)} серверов.'))
          await sleep(5)

@client.event
async def on_message(message):
    embed = (discord.Embed(title='Страница хелп!',description='$help - Увидеть этот список'))
    if message.content.startswith('$help'):
        await message.reply(embed = embed)

client.run('ODc0MzkxMzQ4NDQ5NTM4MTI4.YRGSZg.lL7DwCEfbtb3BbXH8GGiwWvXssc')


And after I created another command:
import discord
import asyncio
from asyncio import sleep

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_ready():
     while True:
          await client.change_presence(status=discord.Status.online, activity=discord.Game("$help"))
          await sleep(5)
          await client.change_presence(status=discord.Status.online,activity=discord.Game(f'{len(client.guilds)} серверов.'))
          await sleep(5)

@client.event
async def on_message(message):
    embed = (discord.Embed(title='Страница хелп!',description='$hello - Заставить бота сказать вам привет!\n$help - Увидеть этот список'))
    if message.content.startswith('$help'):
        await message.reply(embed = embed)

@client.event
async def on_message(message):
    embed = (discord.Embed(title='инфо',description='Я ТОКСИК!'))
    if message.content.startswith('$toxic'):
        await message.reply(embed = embed)

client.run('ODc0MzkxMzQ4NDQ5NTM4MTI4.YRGSZg.lL7DwCEfbtb3BbXH8GGiwWvXssc')

$help command stopped working

Answer the question

In order to leave comments, you need to log in

4 answer(s)
U
UberPool, 2021-08-10
@Wolf_Yout

Use decorator client.command()
Command example:

@client.command()
async def send_text(ctx):
     await ctx.send('test')
     #...more

V
Vindicar, 2021-08-10
@Vindicar

Because you do it through your ass. Instead of using the existing command mechanism, you put a reaction on any message and try to pull out the command text from it yourself. Actually, the problem is that you declared two methods with the same name. One of them will always be covered by the other.
I understand that you read Quickstart , well done. How about reading further ?

S
saico, 2021-08-10
@saico

Use@client.command()

B
Bot-Developer, 2021-08-10
@Bot-Developer

Use @client.command()
Code:

import discord
from discord.ext import commands
import asyncio
from asyncio import sleep

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_ready():
     while True:
          await client.change_presence(status=discord.Status.online, activity=discord.Game("$help"))
          await sleep(5)
          await client.change_presence(status=discord.Status.online,activity=discord.Game(f'{len(client.guilds)} серверов.'))
          await sleep(5)

@client.command()
async def help (ctx):
    embed = (discord.Embed(title='Страница хелп!',description='$hello - Заставить бота сказать вам привет!\n$help - Увидеть этот список'))
    await ctx.reply(embed = embed)

@client.command()
async def toxic (ctx):
    embed = (discord.Embed(title='инфо',description='Я ТОКСИК!'))
    await ctx.reply(embed = embed)

@client.run('Токен бота')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question