作为一个小测试,我正在制作一个不和谐的机器人,它将接收我发送的消息,删除它,并让机器人发送消息。我有一些工作,但我有几个问题。
首先,机器人不会总是删除消息。
有了这段代码
if message.content.startswith("H"):
print("test")
print(message.author)
msg=message.content
await client.delete_message(message)
await client.send_message(message.channel, msg)
机器人有时只会删除我的消息。知道为什么吗?
其次,我希望它只重复我的信息,但是当我这样做时;
if message.author=="Myusername#1234":
print("test")
print(message.author)
msg=message.content
await client.delete_message(message)
await client.send_message(message.channel, msg)
什么都没发生。没有错误,只是没有。有人可以帮忙吗?
P.S:Myusername#1234
只是一个例子,而不是我所投入的。
在第一个代码示例中,您的机器人的消息也将通过if
语句,并且只会陷入写入以“H”开头并删除它们的消息的循环中。
你应该把它更新为类似的东西
if message.content.startswith("H") and message.author.id != "bot_id":
至于第二个代码示例,最好的办法是使用用户ID,因为它们不会更改
if message.author.id == "user_id":
如果你真的想用别的东西,你可以做message.author.name
或message.author.nick