如何在此代码中提及随机成员?
@tree.command(name = 'tinder')
async def tinder(interaction: discord.Interaction):
users = interaction.guild.members
await interaction.response.send_message(f'{interaction.user.mention} deu match com {random.choice(users)} :flushed:')
“interaction.guild.members”只返回机器人用户
我正在使用intents.member
intents = discord.Intents.all()
intents.members = True
从写入命令的服务器中随机选择一个成员,而不是所有服务器
从discord开发者门户启用intents.members,然后使用intents.member。 如果未启用 intent.members,通常会发生这种情况。
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix = "prefix", intents=intents)
尝试使用此代码,它应该可以正常工作。
import discord
from discord.ext import commands
from random import choice
TOKEN = "TOKEN"
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
bot = commands.Bot(command_prefix="/", intents=intents)
@bot.command(name="randomMember")
async def command1(ctx: commands.Context):
random_member = choice(ctx.guild.members)
await ctx.send(f"Random member: {random_member.mention}")
bot.run(TOKEN)