从预定的set discord.py中选择随机数
我有一个功能,每隔几个小时就可以将随机用户贴上一个或否问题。但是,我想要它,因此,当用户响应是/否时,仅当ping ID的消息ID =时,该机器人才会回答。
我遇到的问题是找到一种使Python从整数列表中选择的方法。我可以为ping做到这一点:
USER_ID = ["11111111111", "222222222222", "3333333333333"]
但是问题是,sagess.author.id仅适用于整数,这意味着它们不能用引号。
随机ping的代码是:
newvalue = False
@bot.command(pass_context=True)
async def randum(ctx):
while True:
global USER_ID_FOR_BOT
USER_ID_FOR_BOT = random.choice(USER_ID)
RESPONSES = ["<@" + USER_ID_FOR_BOT + ">" + " Do you want to hear a joke?", "(Other none yes/no questions)"]
possibleresponse = random.choice(RESPONSES)
if possibleresponse == "<@" + USER_ID_FOR_BOT + ">" + " Do you want to hear a joke?":
global newvalue
newvalue = True
print ('Value is TRUE')
await ctx.channel.send(possibleresponse)
await asyncio.sleep(random.randint(minTime, maxTime))
终端告诉我值是真实的,所以我可以说此代码不是问题。然后在on_message中。...
if newvalue == True:
if 'no' in message.content:
if message.channel.id == 988993107368476692:
if message.author.id == USER_ID_FOR_BOT:
await message.channel.send(random.choice(denyresponse))
newvalue = False
return
if 'yes' in message.content:
if message.channel.id == 988993107368476692:
if message.author.id == USER_ID_FOR_BOT:
await message.channel.send(random.choice(jokeresponse))
newvalue = False
return
await bot.process_commands(message)
我需要user_id_for_bot是一个int,但是我不知道如何列出该程序可以选择的每确定ints列表。听起来很简单,但是我真的很难在Google上找到任何东西。
I have a function that pings a random user with a yes or no question every few hours. However, I want it so when the user responds yes/no, the bot will only answer if their message id = that of the ping ID.
The issue I'm running into is finding a way to get python to select from a set list of integers. I could just do this for the ping:
USER_ID = ["11111111111", "222222222222", "3333333333333"]
But the issue is, message.author.id ONLY works for integers, meaning they CAN'T be in quotes.
The code for the randomized ping is:
newvalue = False
@bot.command(pass_context=True)
async def randum(ctx):
while True:
global USER_ID_FOR_BOT
USER_ID_FOR_BOT = random.choice(USER_ID)
RESPONSES = ["<@" + USER_ID_FOR_BOT + ">" + " Do you want to hear a joke?", "(Other none yes/no questions)"]
possibleresponse = random.choice(RESPONSES)
if possibleresponse == "<@" + USER_ID_FOR_BOT + ">" + " Do you want to hear a joke?":
global newvalue
newvalue = True
print ('Value is TRUE')
await ctx.channel.send(possibleresponse)
await asyncio.sleep(random.randint(minTime, maxTime))
The terminal tells me the value is True, so I can say this code isn't the issue. And then in the on_message....
if newvalue == True:
if 'no' in message.content:
if message.channel.id == 988993107368476692:
if message.author.id == USER_ID_FOR_BOT:
await message.channel.send(random.choice(denyresponse))
newvalue = False
return
if 'yes' in message.content:
if message.channel.id == 988993107368476692:
if message.author.id == USER_ID_FOR_BOT:
await message.channel.send(random.choice(jokeresponse))
newvalue = False
return
await bot.process_commands(message)
I need USER_ID_FOR_BOT to be an int, but I have no clue how to make a list of per-determined ints that the program can choose from. It sounds simple, but I genuinely am having difficulty finding anything on google.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
random.choice
是您要在此处使用的内容,以下是文档:random.choice
is what you want to use here, below is from the documentation: