i'm starting using discord.py and i don't understand why my bot does not respond to my test command .the bot is starting correcly and says his line in the channel while starting but do not react to my command
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='$')
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as {0}!'.format(self.user))
channel = client.get_channel(123456789)
await channel.send("online")
@bot.command()
async def test(ctx):
await ctx.send('test')
thank you !
CodePudding user response:
You have defined your bot as bot. However, in your MyClient class you have put client.get_channel which should be bot.get_channel. You're saying it starts fine and sends the message to the channel which is weird. You might have had trouble saving the code or something
CodePudding user response:
First thing is that you don't necessarily need a class attribute you can use @bot.event just fine like this
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='$')
@bot.event
async def on_ready(self):
print('Logged on as {0}!'.format(self.user))
channel = client.get_channel(123456789)
await channel.send("online")
@bot.command()
async def test(ctx):
await ctx.send('test')
or the error in your original code is in two places discord.Client is inbuilt instead you should be declaring bot as well as indentation of bot.command
from discord.ext import commands
bot = commands.Bot(command_prefix='$')
class MyClient(bot):
@bot.event
async def on_ready(self):
print('Logged on as {0}!'.format(self.user))
channel = client.get_channel(123456789)
await channel.send("online")
@bot.command()
async def test(ctx):
await ctx.send('test')
i think that should work the first one i am sure it will work 100% second one not so much since i haven't run these codes rn coz i am busy if you get any other error feel free to ask. Plus i don't think there is any benefit in declaring a class
