繁体   English   中英

我如何禁止使用 Python 和 discord.py 的人?

[英]How I can ban someone with Python and discord.py?

我正在尝试实现一些功能,如果有人发送 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("")

您正在使用 discord.py v0.16 版本中的语法,该版本不再受支持。
请参阅迁移到 v1 的指南,特别是Models are Stateful 部分

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

此外,将来在寻求帮助时,您应该提供完整的回溯。

暂无
暂无

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

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