gpt4 book ai didi

python - discord.py 发送机器人消息然后固定(重写)

转载 作者:行者123 更新时间:2023-11-28 18:58:47 25 4
gpt4 key购买 nike

所以我正在猜测数字机器人。我希望机器人在猜到号码时发送,然后固定机器人发送的消息。我该怎么做?

@client.event
async def on_message(message):
if message.content == str(number) and message.channel.id == 555146955815256065:
author = message.author.id
await message.channel.send("Congratulations <@" + str(author) + ">! You guessed the number, `" + str(number) + "`!")
await message.pin()

我已经这样做了,这将固定用户发送的消息,而不是机器人消息,

感谢任何帮助,谢谢!

最佳答案

您必须定义机器人发送的消息(例如此处为 botmsg)并将其固定。否则它会将 on_message(message) 中定义的消息固定在 bot react 的消息上。

此外,我对消息本身进行了过度处理,因此更容易提及用户并插入数字(您也可以将其作为整数来做,但字符串也可以)。

@client.event
async def on_message(message):
if message.content == str(number) and message.channel.id == 555146955815256065:
botmsg = await message.channel.send(f"Congratulations {message.author.mention}! You guessed the number, `{number}`!")
await botmsg.pin()

关于python - discord.py 发送机器人消息然后固定(重写),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55131396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com