Я новичок в создании ботов Discord, но в настоящее время работаю над ботом для своего сервера, который будет блокировать любого, кто отправляет сообщение в определенном канале, чтобы остановить других ботов.
Я убедился, что для человека совершенно очевидно, что отправка сообщений на этом канале приведет к его блокировке, но бот, скорее всего, не узнает об этом, и его забанят. По какой-то причине при запуске строки await message.author.ban(reason="you are abot and боты съеживаются") ничего не происходит.
Вот полный скрипт:
import discord
from discord.ext import commands
import logging
from dotenv import load_dotenv
import os
load_dotenv()
token = os.getenv("DISCORD_TOKEN")
handler = logging.FileHandler(filename="discord.log", encoding="utf-8", mode="w")
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
intents.moderation = True
bot = commands.Bot(command_prefix="!", intents=intents)
def canBanUser(user: discord.Member):
for role in user.roles:
if role.name == "Mod":
return False
return True
@bot.event
async def on_message(message: discord.Message):
if message.author == bot.user:
return
if message.channel.name == "bot-trap":
canBan = canBanUser(message.author)
if canBan:
await message.channel.send(f"{message.author.mention} get banned noob")
await message.author.ban(reason="you are a bot and bots are cringe")
else:
await message.channel.send(f"{message.author.mention} you are a mod and you can say stuff in this channel without being banned!")
await bot.process_commands(message)
bot.run(token, log_handler=handler, log_level=logging.DEBUG)
Подробнее здесь: https://stackoverflow.com/questions/798 ... iscord-bot