I have a problem with my Python script, which is a Discord bot. The script detects an "Empty Message", even though the message that has been sent into the server does have content, which are commands. Is there a way to fix this? I haven't found one yet.
@client.event
async def on_message(message):
if message.author == client.user:
return
if not message.content:
print(f"Received empty message from user ID: {message.author.id}")
return
messages = [message]
if message.reference is not None:
referenced_message = await message.channel.fetch_message(message.reference.message_id)
if referenced_message.author == client.user and referenced_message.content.startswith('User ID: '):
messages.insert(0, referenced_message)
for msg in messages:
print(f"Received message: '{msg.content}' from user ID: {msg.author.id}")
if msg.content.startswith('!yes'):
# Move approved data to a separate file (e.g., approved.json)
with open('approved.json', 'a') as file:
json.dump(data.pop(0), file, indent=4)
await send_next_data()
await msg.channel.send('Data approved.')
print(f"User Approved the Shown User.")
elif msg.content.startswith('!no'):
# Move rejected data to a separate file (e.g., rejected.json)
with open('rejected.json', 'a') as file:
json.dump(data.pop(0), file, indent=4)
await send_next_data()
await msg.channel.send('Data rejected.')
print(f"User Rejected the Shown User.")
I've added extra print parameters, such as print(f"Received empty message from user ID: {message.author.id}"), added print(f"User Approved the Shown User.") and print(f"User Rejected the Shown User.") and other small changes on other parts of the code.