Код работает отлично, проверки все проходят, но почему-то вылетают ничего не ломающие ошибки
Ошибки:
Traceback (most recent call last):
File "/home/container/.local/lib/python3.12/site-packages/discord/client.py", line 441, in _run_event
await coro(*args, **kwargs)
File "/home/container/main.py", line 25, in on_message
if role in message.author.roles:
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'User' object has no attribute 'roles'
2024-02-17 19:15:17 ERROR discord.client Ignoring exception in on_message
Traceback (most recent call last):
File "/home/container/.local/lib/python3.12/site-packages/discord/client.py", line 441, in _run_event
await coro(*args, **kwargs)
File "/home/container/main.py", line 20, in on_message
if message.channel.name == "?︱win-or-lose" and ":skip_reacts:" not in message.content:
AttributeError: 'DMChannel' object has no attribute 'name'
При этих ошибках код все еще отлично работает и выполняет эти проверки
import discord
import asyncio
import random
from discord.ext import commands
from discord.utils import get,find
bot = commands.Bot(command_prefix="!", help_command=None, intents=discord.Intents.all())
@bot.event
async def on_ready():
print(f"Bot {bot.user} logged in yours ass")
coolrole = "Links"
links = [".com", "https://", ".org", ".net", ".gg"]
@bot.event
async def on_message(message):
await bot.process_commands(message)
if message.channel.name == "?︱win-or-lose" and ":skip_reacts:" not in message.content:
await message.add_reaction("?")
await message.add_reaction("?")
await message.add_reaction("?")
role = message.guild.get_role(1206966962421239839)
if role in message.author.roles:
return
for i in range(len(links)):
if links[i] in message.content:
if "roblox.com" not in message.content and "discord.com" not in message.content and "tenor.com" not in message.content and "discordapp.com" not in message.content:
bad = f'''{message.author.mention}, this link not allowed here :c, Only tenor, roblox and discord allowed ```{message.content}```'''
await message.delete()
await message.author.send(bad)
else:
if " " in message.content or "[" in message.content:
bad = f'''{message.author.mention}, dont write spaces or [, ] in link messages. ;D ```{message.content}```'''
await message.delete()
await message.author.send(bad)
@bot.event
async def on_message_edit(before, after):
role = after.guild.get_role(1206966962421239839)
if role in after.author.roles:
return
for i in range(len(links)):
if links[i] in after.content:
if "roblox.com" not in after.content and "discord.com" not in after.content and "tenor.com" not in after.content and "discordapp.com" not in after.content:
bad = f'''{after.author.mention}, this link not allowed here :c, Only tenor, roblox and discord allowed ```{after.content}```'''
await after.delete()
await after.author.send(bad)
else:
if " " in after.content or "[" in after.content:
bad = f'''{after.author.mention}, dont write spaces or [, ] in link messages. ;D ```{after.content}```'''
await after.delete()
await after.author.send(bad)
@bot.event
async def on_member_update(before, after):
if len(before.roles) < len(after.roles):
new_role = next(role for role in after.roles if role not in before.roles)
if new_role.name in ('Clan Member'):
user = bot.get_user(int(before.id))
channel = bot.get_channel(1187788928246358086)
channel3 = bot.get_channel(1187798241077624904)
newmemmess = f'''**Hello new Welcome to SN_W clan.**
{user.mention}
We are happy to have you with us.
○ You can check out private servers, values, gem donation database and all clan resources in {channel3.mention}.
*Last but not least have fun! All clan members are always there to help you just don't be shy to ask.*'''
await channel.send(newmemmess)
@bot.command()
async def huge(ctx, member: discord.Member):
emoji = bot.get_emoji(1190789979945836584)
huge = f'''**CONGRATULATE?{emoji}?! CONGRATULATE?{emoji}?! CONGRATULATE?{emoji}?!**
{member.mention} HATCHED A HUUUUUUUUGEEEEE ???
**CONGRATULATE?{emoji}?! CONGRATULATE?{emoji}?! CONGRATULATE?{emoji}?!**'''
await ctx.send(huge)
@bot.command()
@commands.has_role(1206976037901172796)
async def why(ctx, member: discord.Member, *, information):
bully = f'''**Hello dear user. I am need to say you this information:**
{member.mention} {information}
{ctx.author.mention} - This person ask me to say this information for you <3'''
await member.send(bully)
@bot.command()
@commands.has_role(1207780282296434789)
async def ga(ctx, item):
mess = await ctx.send(f'Its a {item}')
await mess.add_reaction("?")
await asyncio.sleep(5)
mess = await ctx.channel.fetch_message(mess.id)
if yes_react := discord.utils.get(mess.reactions, emoji='?'):
async for user in yes_react.users:
user = random.choice(user)
print("NOT WORKS RN")
@bot.command()
async def lv(ctx, member: discord.Member):
bully = f'''{member.mention}, I am love you <3'''
await member.send(bully)
bot.run("")
Ответы (1 шт):
Автор решения: jillstr
→ Ссылка
Если посмотреть на ошибку, то можно сказать, что вы используете команду в личном чате (лс) с ботом, т.к message.author возвращает класс User. Попробуйте использовать команду на сервере.