jeudi 23 juin 2022

Choose random number from pre-determined set Discord.py

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.




Aucun commentaire:

Enregistrer un commentaire