0
votes

I'm making a bot on Discord.py and I'm trying to set the channel I want to send a message to using an argument. The code is this:

@client.command()
async def send(ctx, arg1):
    channel = client.get_channel(arg1)
    await channel.send('Message')

When I type the channel id instead of arg1, it works, but when I type the command on Discord (!send 282772187812) it doesn't work and I get this error: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'send'

Thanks in advance.

1
Have you tried using a try : except: to send a message on error and attempt to resume executionelite gamer88
No, I haven't tried thatMmods GTA V
discordpy.readthedocs.io/en/latest/api.html shows the channel id should be an int, but I believe arg1 is a string here. Don't know if it matters but you may want to try casting arg1 to an int.backcab

1 Answers

0
votes

As @backcab said, you can either convert arg1 to an integer or use channel converters from ext.commands.

Solution 1

@client.command()
async def send(ctx, arg1):
    channel = client.get_channel(int(arg1))
    await channel.send('Message')

Solution 2

@client.command()
async def send(ctx, channel: discord.TextChannel):        
    await channel.send('Message')