繁体   English   中英

踢出角色为 Discord bot Python 的成员

[英]Kick members with role Discord bot Python

我想添加一个功能来踢出具有特定角色的用户。 但没有任何效果。我一直在寻找解决方案,但他们都没有帮助。 有时团队工作,但没有确定合适角色的人,没有人被踢

from discord.ext import commands
import sys
import urllib.parse
import urllib.request
import re
from discord.ext.commands import *
import discord
from discord.ext.commands import has_permissions

intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix = "!", intents=intents)

@bot.command()
@commands.has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason=None):
    if reason==None:
      reason=" no reason provided"
    await ctx.guild.kick(member)
    await ctx.send(f'Пользователь {member.mention} был кикнут по причине {reason}')

@bot.command()
@commands.has_permissions(ban_members = True)
async def ban(ctx, member : discord.Member, *, reason = None):
    await member.ban(reason = reason)


@bot.command()
@commands.has_permissions(administrator = True)
async def unban(ctx, *, member):
    banned_users = await ctx.guild.bans()
    member_name, member_discriminator = member.split("#")

    for ban_entry in banned_users:
        user = ban_entry.user

        if (user.name, user.discriminator) == (member_name, member_discriminator):
            await ctx.guild.unban(user)
            await ctx.send(f'Unbanned {user.mention}')
            return

@bot.command()
@commands.has_permissions(administrator = True)
async def clearall(ctx):
  await ctx.channel.purge()

bot.run("Token")
import discord 
from discord.ext import commands
from discord.ext.commands import has_permissions

bot = commands.Bot(command_prefix='.')

@bot.command()
@has_permissions(administrator=True)
async def kickMembers(ctx, role: discord.Role, reason: str = None):
    await ctx.reply('Kicking members')

    for member in role.members:
        await member.kick(reason=reason)

    await ctx.reply('Members kicked')

此代码有效,但看不到具有该角色的人。 国王的尝试正在进行中,但有角色的人没有踢

嘿唯一的小问题是这条线

意图 = discord.Intents.default()

机器人基本上没有权利用默认意图踢人

如何解决它替换这条线

intents = discord.Intents.default()

intents = discord.Intents.all()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM