Nextcord:如何将消息发送到 cogs 中的特定频道?
Nextcord: How do I send a message to a specific channel in cogs?
我正在使用 python 3.10.2.
我正在使用 Nextcord 向我的 discord 机器人创建一个 edit/delete 日志记录功能,然后机器人会发送它到我的日志频道。
class Logs(commands.Cog):
def __init__(bot, self):
self.bot = bot
@commands.Cog.listener()
async def on_message_delete(self, message):
embed = nextcord.Embed(
title=f"`{message.author.name}` deleted a message. | User id: <{message.author.id}>", description=f"{message.content}", color=0xffffff)
channel = bot.get_channel(950093169515696181)
await channel.send(embed=embed)
@commands.Cog.listener()
async def on_message_edit(self, message_before, message_after):
embed = nextcord.Embed(
title=f"`{message_before.author.name}` edited a message. | User id: {message_before.author.id}", color=0xffffff)
embed.add_field(name="Before edit:",
value=f"{message_before.content}", inline=False)
embed.add_field(name="After edit:",
value=f"{message_after.content}", inline=False)
channel = bot.get_channel(950093169515696181)
await channel.send(embed=embed)
def setup(bot):
bot.add_cog(Logs(bot))
但是当我尝试触发 edit 或 delete 时,我收到错误消息:
File "F:\bot\cogs\logger.py", line 20, in on_message_delete
await channel.send(embed=embed)
AttributeError: 'NoneType' object has no attribute 'send'
如果有人知道如何解决这个问题,我将不胜感激。我也查看了官网,但它和我的代码一样,所以... (https://nextcord.readthedocs.io/en/latest/faq.html#how-do-i-send-a-message-to-a-specific-channel)
是self.bot.get_channel(id)
我正在使用 python 3.10.2. 我正在使用 Nextcord 向我的 discord 机器人创建一个 edit/delete 日志记录功能,然后机器人会发送它到我的日志频道。
class Logs(commands.Cog):
def __init__(bot, self):
self.bot = bot
@commands.Cog.listener()
async def on_message_delete(self, message):
embed = nextcord.Embed(
title=f"`{message.author.name}` deleted a message. | User id: <{message.author.id}>", description=f"{message.content}", color=0xffffff)
channel = bot.get_channel(950093169515696181)
await channel.send(embed=embed)
@commands.Cog.listener()
async def on_message_edit(self, message_before, message_after):
embed = nextcord.Embed(
title=f"`{message_before.author.name}` edited a message. | User id: {message_before.author.id}", color=0xffffff)
embed.add_field(name="Before edit:",
value=f"{message_before.content}", inline=False)
embed.add_field(name="After edit:",
value=f"{message_after.content}", inline=False)
channel = bot.get_channel(950093169515696181)
await channel.send(embed=embed)
def setup(bot):
bot.add_cog(Logs(bot))
但是当我尝试触发 edit 或 delete 时,我收到错误消息:
File "F:\bot\cogs\logger.py", line 20, in on_message_delete
await channel.send(embed=embed)
AttributeError: 'NoneType' object has no attribute 'send'
如果有人知道如何解决这个问题,我将不胜感激。我也查看了官网,但它和我的代码一样,所以... (https://nextcord.readthedocs.io/en/latest/faq.html#how-do-i-send-a-message-to-a-specific-channel)
是self.bot.get_channel(id)