Главный файл / Main file
import os
import disnake
from disnake.ext import commands
from ds1 import TOKEN
intents=disnake.Intents.all()
bot = commands.Bot(command_prefix="/", intents=intents, test_guilds=[1268858555616854106])
intents.members = True
@bot.event
async def on_ready():
print(f"Бот {bot.user} готов к работе")
@bot.command()
@commands.is_owner()
async def load(ctx, extension):
bot.load_extension(f"cogs.{extension}")
@bot.command()
@commands.is_owner()
async def unload(ctx, extension):
bot.unload_extension(f"cogs.{extension}")
@bot.command()
@commands.is_owner()
async def reload(ctx, extension):
bot.reload_extension(f"cogs.{extension}")
for filename in os.listdir("A:/test/discord/course1/cogs"):
if filename.endswith(".py"):
bot.load_extension(f'cogs.{filename[:-3]}')
bot.run(TOKEN)
Cog файл / file
import disnake
from disnake.ext import commands
class Members(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_member_join(self, member):
guild = self.bot.get_guild(1268873156441931806)
role = disnake.utils.get(member.guild.roles, id=1268865812350111775)
embed = disnake.Embed(title="Title", description=f"Description {member.mention}", color=0x27152f)
await member.add_roles(role)
await guild.send(embed=embed)
def setup(bot):
bot.add_cog(Members(bot))
Ошибка / Error
Ignoring exception in on_member_join
Traceback (most recent call last):
File "A:\Programms\Python\Lib\site-packages\disnake\client.py", line 703, in _run_event
await coro(*args, **kwargs)
File "a:\test\discord\course1\cogs\member.py", line 14, in on_member_join
await guild.send(embed=embed)
^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'send'