-1

I created a join command for my discord.py bot, but if ill specify a channel name with spaces, it wont connect to him. It throws an AttributeError, which indicates that the channel could not be found.

    @commands.command()
    async def join(self, ctx, channelname):
        channel = discord.utils.get(ctx.guild.channels, name=channelname)
        await channel.connect()
1
  • Can you enclose the channel name in quotes name=‘My Channel Name’, perhaps?
    – esqew
    Dec 27, 2020 at 12:39

1 Answer 1

2

You need to add a * before the final argument to take in the full string like this:

async def join(ctx, *, args):

So your function will look like this:

@commands.command()
async def join(ctx, *, channelname):
    channel = discord.utils.get(ctx.guild.channels, name = channelname)
    await channel.connect()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.