Вопрос Бан дискорд ботом

  • Автор темы Автор темы D3FTY
  • Дата начала Дата начала
Начинающий
Начинающий
Статус
Оффлайн
Регистрация
9 Июл 2023
Сообщения
76
Реакции
0
Код:
Expand Collapse Copy
@bot.command(name="ban")
async def ban(self, ctx, user: discord.Member = None, *, reason='not specified'):
    guild = ctx.guild
    await ctx.send(f"{ctx.author.display_name} banned a user {user.display_name}. Reason: {reason}")
    await guild.ban(user)

не могу бан сделать
подскажите или дайте код

Библеотека import discord
from discord.ext import commands
 
Код:
Expand Collapse Copy
@bot.command(name="ban")
async def ban(self, ctx, user: discord.Member = None, *, reason='not specified'):
    guild = ctx.guild
    await ctx.send(f"{ctx.author.display_name} banned a user {user.display_name}. Reason: {reason}")
    await guild.ban(user)

не могу бан сделать
подскажите или дайте код

Библеотека import discord
from discord.ext import commands
попробуй

async def ban(ctx, member : discord.Member, *, reason = None):
await member.ban(reason = reason)
 
Код:
Expand Collapse Copy
@bot.command(name="ban")
async def ban(self, ctx, user: discord.Member = None, *, reason='not specified'):
    guild = ctx.guild
    await ctx.send(f"{ctx.author.display_name} banned a user {user.display_name}. Reason: {reason}")
    await guild.ban(user)

не могу бан сделать
подскажите или дайте код

Библеотека import discord
from discord.ext import commands
зачем тебе self если у тебя нет когов, умник
 
Код:
Expand Collapse Copy
@bot.command(name="ban")
async def ban(self, ctx, user: discord.Member = None, *, reason='not specified'):
    guild = ctx.guild
    await ctx.send(f"{ctx.author.display_name} banned a user {user.display_name}. Reason: {reason}")
    await guild.ban(user)

не могу бан сделать
подскажите или дайте код

Библеотека import discord
from discord.ext import commands
Python:
Expand Collapse Copy
import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.members = True

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.slash_command(name="ban", description="Забанить пользователя")
async def ban(ctx, user: discord.Member, reason: str = 'не указана'):
    guild = ctx.guild
    author = ctx.author

    if not author.guild_permissions.ban_members:
        await ctx.send("У вас нет прав на бан участников.")
        return

    try:
        await guild.ban(user)
        await ctx.send(f"{author.display_name} забанил пользователя {user.display_name}. Причина: {reason}")
    except discord.Forbidden:
        await ctx.send("У меня нет прав на бан участников.")
    except discord.HTTPException:
        await ctx.send("Произошла ошибка при попытке забанить пользователя.")

bot.run('YOUR_BOT_TOKEN')
и советую использовать слэш команды
 
Команда /ban и /unban:
Expand Collapse Copy
@router.message(Command("ban"))
async def func_ban(message: types.Message, command: CommandObject, bot: Bot):
    reply_message = message.reply_to_message

    if not reply_message or not await is_admin(message, bot):
        await message.reply("<b>  Произошла ошибка!</b>")
        return
    
    date = parse_time(command.args)
    mention = reply_message.from_user.mention_html(reply_message.from_user.first_name)

    with suppress(TelegramBadRequest):
        await bot.ban_chat_member(chat_id=message.chat.id, user_id=reply_message.from_user.id, until_date=date)
        await message.answer(f" Пользователь <b>{mention}</b> был заблокирован!")

@router.message(Command("unban"))
async def func_unban(message: types.Message, bot: Bot):
    reply_message = message.reply_to_message

    if not reply_message or not await is_admin(message, bot):
        await message.reply("<b>  Произошла ошибка!</b>")
        return
    
    await bot.unban_chat_member(chat_id=message.chat.id, user_id=reply_message.from_user.id, only_if_banned=True)
    await message.answer(" Блокировка была снята")
 
Назад
Сверху Снизу