【问题标题】:How I can ban someone with Python and discord.py?如何使用 Python 和 discord.py 禁止某人?
【发布时间】:2020-01-20 06:20:31
【问题描述】:

我正在尝试实现一些功能,如果有人发送 Discord 邀请,他们会被禁止,但我每次都会收到相同的错误:

'BotLibertarin' object has no attribute 'ban'

代码如下:

import discord
from discord.ext import commands


class BotLibertarin(discord.Client):
    client = commands.Bot(command_prefix='.')
    @client.event   
    async def on_ready(self):
       print(f"Logged on as {self.user}")

    @client.event
    async def on_message(self, message):
        print(f"message from {message.author} what he said {message.content} and the id is {message.author.id}")
       if message.author == client.user:
           return
      #ban for invinte on discord
    if message.content.startswith("https://discord.gg/"):
        for member in client.get_all_members():
            print("entrou dentro do if")
            if member.id == message.author.id:
                print("vai tomar ban KKKKKK")
                banned = member.id

                try:
                    await client.ban(banned,delete_message_days=2)
                    await message.channel.send(f"User {banned} sended a discord invite")
                except Exception as e:
                    print(f"you got error {e}")
client = BotLibertarin()
client.run("")

【问题讨论】:

    标签: python bots discord discord.py


    【解决方案1】:

    您正在使用不再支持的 discord.py v0.16 版本中的语法。
    请参阅the guide for migrating to v1,特别是Models are Stateful section

    您应该使用Member.banGuild.ban 而不是Client.ban
    在这种情况下,相关行将是await member.ban(delete_message_days=2)

    另外,今后在寻求帮助时,您应该提供完整的回溯。

    【讨论】:

    • 我刚刚对使用的成员做了一个小改动,我得到了这个错误:ban() 需要 1 个位置参数,但给出了 2 个
    • 如果没有完整的回溯,就不可能确定您的确切问题是什么,但您不应该将任何位置参数传递给Member.ban
    猜你喜欢
    • 1970-01-01
    • 2019-07-28
    • 2021-09-16
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2021-06-20
    • 2020-09-26
    • 2017-01-20
    相关资源
    最近更新 更多