Reputation: 1
I made a discord.py bot for one of our members, as a joke. im testing it out and it doesnt work at all. can someone tell me what can be wrong with this code?
from http import client
import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
client.run(TOKEN)
@client.event
async def on_message(message):
await client.process_commands(message) # add this if also using command decorators
if message.author.id == 300677572683890688 and "tranime" in message.content.lower():
await message.delete()
await message.channel.send(f"You are in the process of behavioural therapy. please do not attempt to bypass it, {message.author.mention}")
Upvotes: 0
Views: 117
Reputation: 3602
The structure, how you build the bot, is wrong in many ways, that could cause the error.
To run the bot,
client.run(TOKEN)
always belongs at the end of your code!
To process commands, you put
await client.process_commands(message)
at the end of your on_message
event, even though this is not necessary here as you just use discord.Client()
.
A new structure could be:
client = discord.Client()
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
@client.event
async def on_message(self, message):
if message.author.id == 300677572683890688 and "tranime" in message.content.lower():
await message.delete()
await message.channel.send(f"Your message here")
await client.process_commands(message)
client.run(TOKEN)
The code should also be indented correctly, otherwise there may be problems.
Upvotes: 1