使用特定用户ID向用户发送不一致的bot消息

2024-10-01 13:26:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我在一个discord服务器中有一个bot,当他们键入一个名为hello的命令时,bot将从列表中的随机选择中做出响应。在

我试图让机器人以不同的方式响应,如果它是一个非常特定的用户id

这不管用

@bibi.command()
async def hello():
    if message.author.id == ('279460450637185024'):
        choicesa = ('get away', 'dont greet me', 'youre wasting my time', 'Hallo', 'oh god its you', '....' , 'dude go away' , 'WHAT DO YOU WANT' , 'HIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII' , 'i dont talk to democrats')
        await bibi.say(random.choice(choicesa))
    elif message.author.id == ('80971950054187008'):
        choicesl = ('lauren...', 'hi. lauren.')
        await bibi.say(random.choice(choicesl))

意思是消息没有被定义,现在我明白了,我以为它是在discords库中定义的,但它没有。在

我该怎么做?在


Tags: idmessagehellobotrandomawaitauthorsay
3条回答

只需尝试在函数中添加ctx作为参数,然后将其添加为启动器。在

@bibi.command(pass_context=True)
 async def hello(ctx):
       if ctx.message.author.id == '279460450637185024':
           choicesa=['hi','hello','okay?']
           await bibi.say(random.choice(choicesa))

如果使用的是重写版本的d.py,则必须通过执行async def hello(ctx):ctx参数传递给hello。那么在重写中你不能使用bot.say(或bibi.say)。您必须使用ctx.send(message)而不是bibi.say(message)。在

我知道它会搞乱你所有的其他命令,但如果你像我下面那样做,它会起作用的。在

@client.event
async def on_message():
if message.content == "hello":
  if message.author.id == ('279460450637185024'):
    choicesa = ('get away', 'dont greet me', 'youre wasting my time', 'Hallo', 'oh god its you', '....' , 'dude go away' , 'WHAT DO YOU WANT' , 'HIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII' , 'i dont talk to democrats')
    await bibi.say(random.choice(choicesa))
  elif message.author.id == ('80971950054187008'):
    choicesl = ('lauren...', 'hi. lauren.')
    await bibi.say(random.choice(choicesl))

相关问题 更多 >