Discord Bot Not Sending Messages To Specified Channels
Hello,
I'm creating a discord bot to log actions and send them to specific channels. Every time I run my code I get no errors but as soon as I type in the command/word used I get an error. I am just trying to log actions into another channel.
I haven't set this section up yet:
bot = discord.ext.commands.Bot(command_prefix = "$");
Here is my code:
import os
import discord
from discord.ext import commands
bot = discord.ext.commands.Bot(command_prefix = "$");
client = discord.Client()
# @client.event
# async def on_message(message):
# id = client.get_guild(940403791092670464)
@client.event
async def on_ready():
print(f"{client.user} logged in now!")
@client.event
async def on_message(message):
if message.content.startswith("$help"):
response = print (f"@help command was used")
await message.channel.send(f"{message.author.mention} help stuff")
elif "fudge" in message.content:
await message.delete()
response = print(f"You're not allowed to say those words {message.author.mention} Word Used: Fudge")
await message.channel.send(f"You're not allowed to use those words {message.author}.")
elif "female dog" in message.content:
channel = bot.get_channel(943040534165991485)
await channel.send(f"{message.author.mention} Said the word female dog.")
await message.channel.send(f"You're not allowed to say those words {message.author.mention}")
await message.delete()
response = print (f"Logging actions.")
my_secret = os.environ['TOKEN']
client.run(my_secret)
Here is my Err:
- Ignoring exception in on_message
- Traceback (most recent call last):
- File "/home/runner/Discord-Bot/venv/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event await coro(*args, **kwargs)
- File "main.py", line 31, in on_message
- await channel.send(f"{message.author.mention} Said the word Food.")
- AttributeError: 'NoneType' object has no attribute 'send'
Anything helps!
channel
is None, which means thatbot.get_channel(943040534165991485)
must be returning None. That in turn means that it couldn't find the channel you asked for. – Kemp