As a little test, I'm making a bot for discord that will take a message I send, delete it, and have the bot send the message. I've got some stuff working, but I have a couple of problems.
First, the bot won't always delete messages.
With this code
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)
the bot will only sometimes delete my message. Any idea why?
Second, I want it to only repeat my messages, but when I do this;
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)
Nothing happens. No error, just nothing. Can anyone help?
PS: Myusername#1234
is just an example, and not what I'm putting in.
In the first code example, your bots' message will also go through the if
statement and will just be stuck in a loop of writing messages that start with "H" and deleting them.
You should update it to something like
if message.content.startswith("H") and message.author.id != "bot_id":
As for the second code example, your best bet is to use user IDs since they don't change
if message.author.id == "user_id":
If you really want to use something else you can do message.author.name
or message.author.nick
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.