我试图解决这个问题已经好几个小时了,但是我不明白用户的“自我”是什么。
async def giveaway(ctx):
user_list = []
reaction = discord.Reaction
await ctx.send('?')
time.sleep(5)
users = await reaction.users()
async for user in users:
user_list.append(user)
答案 0 :(得分:1)
这就是我想您要尝试做的。该机器人将发送一条消息,对其进行添加反应,等待一段时间,然后随机选择其中一个人
from discord.ext import commands
from discord.utils import get
from typing import Optional
from random import choice
import asyncio
bot = commands.Bot("!")
@bot.command()
async def giveaway(ctx, timeout: Optional[int] = 60, *, text = "Giveaway"):
emoji = "\N{HAPPY PERSON RAISING ONE HAND}"
message = await ctx.send(text)
await message.add_reaction(emoji)
await asyncio.sleep(timeout)
message = await message.channel.fetch_message(message.id)
reaction = get(message.reactions, emoji=emoji)
users = [user async for user in reaction.users() if user.id != bot.user.id]
await ctx.send(f"Congrats {choice(users).mention}")
bot.run("token")