discord.py - 我如何随机提及一个成员

问题描述 投票:0回答:2

如何在此代码中提及随机成员?

@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

从写入命令的服务器中随机选择一个成员,而不是所有服务器

python discord discord.py slash mention
2个回答
0
投票

discord开发者门户启用intents.members,然后使用intents.member。 如果未启用 intent.members,通常会发生这种情况。

intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix = "prefix", intents=intents)

0
投票

尝试使用此代码,它应该可以正常工作。

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)
© www.soinside.com 2019 - 2024. All rights reserved.