While updating a discord bot I was unable to implement a new command it can respond to, the first one works correctly while the second one only responds with 400 Bad Request (error code: 50006).
import random
def handle_response(message) -> str:
p_message = message.lower()
if "gub" in p_message:
return "GUB."
if "roll" in p_message:
result = random.randrange(1,6)
return f"Rolling a d6...nYou rolled a {str(result)}!"
import discord
import responses
intents = discord.Intents.default()
intents.message_content = True
async def send_message(message, user_message, is_private):
try:
response = responses.handle_response(user_message)
await message.author.send(response) if is_private else await message.channel.send(response)
except Exception as e:
print(e)
def run_discord_bot():
token = "nope"
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'{client.user} is now running.')
@client.event
async def on_message(message):
if message.author == client.user:
return
username = str(message.author)
user_message = str(message.content)
channel = str(message.channel)
print(f"{username} said: '{user_message}' ({channel})")
if user_message[:4] == 'GUB!':
user_message = user_message[4:]
await send_message(message, user_message, is_private=False)
else:
pass
client.run(token)
I have tried to make the second string a simple 3 letter string like the first one, commented out the first one entirely, changed the names of all of the variables to make sure the variable name and the content searched for were not conflicting, each time it returns the same response.
Confusingly changing both the user message prefix string and the first if statement string by one letter breaks the prefix detection, not working for the new or old strings.
REDACTED is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.