'Why my Discord bot always sends duplicated message?
As the title says, when my Discord bot tries to send messages, it always sends the message twice!
I know where the problem is in the code, but I don't know how to fix it.
Code about sending messages:
for i in range(len(final_msg_list)):
new_log = str(message.channel) + "/" + str(client.user) + ":\n" + str(final_msg_list[i-1]) + "\n\n"
log_writter.write_log(new_log)
if isinstance(final_msg_list[i], discord.File):
await message.channel.send(file=final_msg_list[i])
elif isinstance(final_msg_list[i], discord.Embed):
await message.channel.send(embed=final_msg_list[i])
elif isinstance(final_msg_list[i], str):
await message.channel.send(final_msg_list[i])
The bot's log:
[2022-04-15 PM 12:11:42]Channel/me#5877:
y!test
[2022-04-15 PM 12:11:42]Channel/Bot#0359:
test
[2022-04-15 PM 12:11:42]Channel/Bot#0359:
test
And sorry for my bad English...
UPDATE: I found a way to solve that problem!
for i in range(len(final_msg_list)):
current_msg = final_msg_list[i]
if isinstance(current_msg, discord.File):
await message.channel.send(file=final_msg_list[i])
elif isinstance(current_msg, discord.Embed):
await message.channel.send(embed=final_msg_list[i])
elif isinstance(current_msg, str):
await message.channel.send(final_msg_list[i])
I set a new variable: current_msg = final_msg_list[i], and change every final_msg_list[i] into current_msg, and that works!
But I still don't know how this work...?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
