【发布时间】:2021-11-12 18:40:36
【问题描述】:
我的代码返回此错误NoneType object has no attribute 'send'
这是我的代码
import discord
import os
from discord.ext import commands
client = discord.Client()
class Logging(commands.Cog):
"""Sets up logging for you guild"""
def __init__(self, client):
self.bot = client
async def __error(self, ctx, error):
if isinstance(error, commands.BadArgument):
await ctx.send(error)
@commands.Cog.listener()
async def on_message_delete(self, message,):
deleted = embed = discord.Embed(
description=f"Message deleted in {message.channel.mention}", color=0x4040EC
).set_author(name=message.author, url= discord.Embed.Empty, icon_url=message.author.avatar_url)
channel = client.get_channel(888600482317213786)
deleted.add_field(name="Message", value=message.content)
deleted.timestamp = message.created_at
await channel.send(embed=deleted)
def setup(client):
client.add_cog(Logging(client))
我在我的 cogs 中而不是在 main.py 中这样做
【问题讨论】:
-
我建议您使用 config.py 文件之类的文件来存储服务器变量,如频道 ID 或角色 ID,并通过变量名引用它们。这样一来,您在确定这些 ID 的过程中就不会那么头疼了。
-
请在代码块中包含所有代码。并修复缩进,因为含义可以随着不同的缩进而改变。它可能会要求您添加描述,但几行就可以了。不要使用垃圾邮件,而是添加代码应该做什么的描述。
标签: python-3.x discord.py