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:
Anything helps!
Use fetch_channel()
instead of get_channel()
. In discord.py as a rule of thumb fetch_something()
makes an API call while get_something()
tries to get it from the cache.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.