Try random.choice(message.guild.members) instead of random.choice(Channel.members) to get the list of members in the server
Because getting a random member from a text channel is same as from the entire server
And then try message.channel.send(f'{randomMember.mention} is the best')
And also, the bot will mention only itself unless you enable the Privileged Gateway Intents for your bot by going to https://discord.com/developers/applications/{your_bot's_client_id_goes_here}/bot and enable Server Members Intent to make your bot get access to server members list
And also use @bot.command instead of tons of if-else statements for each command inside on_message
Code:
import discord
from discord.ext.commands import Bot
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot('_', intents=intents)
@bot.command()
async def best(ctx):
randomMember = random.choice(ctx.guild.members)
await ctx.send(f'{randomMember.mention} is the best')
If still the above code doesn't work for you...
Change this
@bot.event
async def on_message(message):
# do all your stuff here
into this
@bot.listen('on_message')
async def whatever_you_want_to_call_it(message):
# do stuff here
# do not process commands here
And if you still want to use the on_message with if statements, then use this code
@bot.event
async def on_message(message):
randomMember = random.choice(message.guild.members)
await message.channel.send(f'{randomMember.mention} is the best')
Tell me if its not working for you...