Reputation: 1
This is my code, but no matter what I try it's only tagging the bot? Do you know what I'm doing wrong? I've spent hours on this and I've not been able to figure it out.
@client.command(pass_context=True)
async def test(ctx):
user = random.choice(ctx.message.channel.guild.members)
await ctx.send(f'{user.mention} Youre the best')
I'm trying to get it to tag any random user.
Upvotes: 0
Views: 98
Reputation: 321
As @DK404 has already mention, you probably didn't enable the Server Members Intent on Discord Developers.
Also check if you have enabled the intent for your bot too. You can do that by adding the intents
parameter to your bot instance:
client = discord.Client(..., intents = discord.Intents.all())
After you do that try running the bot again.
By the way ctx.message.channel.guild.members
is the same as ctx.guild.members
Upvotes: 0
Reputation: 11
Most likely, you did not give the bot permission to receive users information (SERVER MEMBERS INTENT) on the site Discord Developers in the Privileged Gateway Intents section.
Upvotes: 1
Reputation: 452
code is only mentioning the bot, which is executing the command!
Try this:
@client.command(pass_context=True)
async def test(ctx):
members = [member for member in ctx.message.channel.guild.members if not member.bot]
if not members:
await ctx.send("There are no non-bot members in this guild.")
return
user = random.choice(members)
await ctx.send(f'{user.mention} You're the best')
Upvotes: 0