因此,关于bot.wait_for()协程的现代文档不是非常详细,并且我很难使它与反应配合使用。希望能得到反馈。
带有Discord.py的Python 3
## Test Role Add
@kelutralBot.command(name='testreaction')
async def testReaction(ctx):
member = ctx.message.author
message = await ctx.send("This is a test message.")
emojis = ['\u2642','\u2640','\u2716']
for emoji in emojis:
await message.add_reaction(emoji)
def check(reaction, user):
return user == message.author and str(reaction.emoji) == '\u2642'
try:
reaction, user = await kelutral.wait_for('reaction_add', timeout=60.0, check=check)
except asyncio.TimeoutError:
await ctx.send("Window has passed to self-assign pronouns. Please DM a mod if you would still like to do so.")
else:
print(reaction)
male = get(member.guild.roles, name="He/Him")
await member.add_roles(male)
print("Assigned " + member.name + " He/Him pronouns.")
答案 0 :(得分:3)
两件事错了。
首先,不要在同一命令中使用import cupy as cp
arr = cp.random.choice(cp.arange(-3, 3), size = (10000, 100))
zrs = cp.count_nonzero(x, axis = 1); cp.any(zrs >= x)
和Client
。 Bot
就足够了。
第二,Discord的Unicode表情符号被视为Bot
,这是最大的问题。
一旦我们解决了问题,一切都会按预期进行。
答案 1 :(得分:1)
这里的问题是,您正在检查发送响应的人是否是包含该消息的消息的作者,而该消息仅由做出反应的机器人满意。还可以考虑改用角色ID(服务器设置>角色>左击角色>右击角色>复制ID)。您还希望在整个命令中与kelutral
或kelutral Bot
保持一致。
@kelutralBot.command(name='testreaction')
async def testReaction(ctx):
member = ctx.message.author
message = await ctx.send("This is a test message.")
emojis = ['\u2642','\u2640','\u2716']
for emoji in emojis:
await message.add_reaction(emoji)
def check(reaction, user):
return user == member and str(reaction.emoji) == '\u2642' # check against the member who sent the command, not the author of the message
try:
reaction, user = await kelutralBot.wait_for('reaction_add', timeout=60.0, check=check)
except asyncio.TimeoutError:
await ctx.send("Window has passed to self-assign pronouns. Please DM a mod if you would still like to do so.")
else:
print(reaction)
male = ctx.message.guild.get_role(ROLE_ID_GOES_HERE) # put your role ID here #
await member.add_roles(male)
print(f"Assigned {member.name} He/Him pronouns.")
请记住,您的代码仅适用于“男性”角色,您必须实现其他检查功能才能将其用于所有功能。