不和谐机器人不向指定信道发送消息
你好,
我正在创建一个不和谐的机器人来记录操作并将它们发送到特定的频道。每次我运行我的代码,我没有错误,但我一输入命令/字使用,我就会得到一个错误。我只是想把行动记录到另一个频道。
我还没准备好这一节:
bot = discord.ext.commands.Bot(command_prefix = "$");
这是我的代码:
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)
这是我的错误:
on_message
)
任何事都有帮助!
发布于 2022-02-15 13:41:37
使用fetch_channel()
而不是get_channel()
。在discord.py中,作为一项经验规则,fetch_something()
进行API调用,而get_something()
试图从缓存中获取它。
https://stackoverflow.com/questions/71125299
复制相似问题