【问题标题】:Python3 Discord Module No Attribute ClientPython3 Discord 模块无属性客户端
【发布时间】:2018-02-15 12:00:26
【问题描述】:

我收到了 Py3 中的 Python Discord Message Mass Prune Script。 但是在此之前有一些错误。 它以前可以工作,但现在它给了我一些错误 它以前没有给我。

import discord
import asyncio

client = discord.Client()

@client.event
async def on_ready():
    print(' ')
    print('Lorem')
    print('ipsum')
    print('dolor')
    print('amet')
    print('sit')
    print('consectetur')
    print('Logged in as:', client.user.name)
    print('UID:',client.user.id) 
    print('Discord version:',discord.__version__)
    print('----------')
    print('Connected to:')
    for server in client.servers:
        print(' -',server.name)

# Define commands
@client.event
async def on_ready():
    if message.author == client.user:
        commands = []
        z = 0
        for index, a in enumerate(message.content):
            if a == " ":
                commands.append(message.content[z:index])
                z = index+1
        commands.append(message.content[z:])
    
        # MASS DELETE OWN MESSAGES
        if commands[0] == 'xc':
            if len(commands) == 1:
                async for msg in client.logs_from(message.channel,limit=9999):
                    if msg.author == client.user:   
                        try:
                            await client.delete_message(msg)
                        except Exception as x:
                            pass
            elif len(commands) == 2:
                user_id = ''
                for channel in client.private_channels:
                    if commands[1] in str(channel):
                        if str(channel.type) == 'private':
                            user_id = str(channel.id)
                async for msg in client.logs_from(discord.Object(id=user_id),limit=9999):
                    if msg.author == client.user:
                        try:
                            await client.delete_message(msg)
                        except Exception as x:
                            pass
                        
client.run("TOKEN HERE",bot=False)

使用 Py3 Pip,我安装了脚本所需的 discord 和 asyncio(所需模块)。 在第 4 行 (client = discord.Client()) 它会抛出错误

Traceback (most recent call last):
  File "discord.py", line 1, in <module>
    import discord
  File "C:\Program Files\Python36\discord.py", line 4, in <module>
    client = discord.Client()
AttributeError: module 'discord' has no attribute 'Client'

【问题讨论】:

    标签: python-3.x discord discord.py


    【解决方案1】:

    您的程序名为discord.py。这掩盖了真正的discord 模块。将程序称为其他名称。

    【讨论】:

      【解决方案2】:

      将您的文件名从 discord.py 更改为另一个,例如 discord_message.py

      因为它只从你的操作系统导入不和谐

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-11-06
        • 2019-04-28
        • 2020-10-13
        • 2017-03-10
        • 2023-03-08
        • 1970-01-01
        • 1970-01-01
        • 2019-10-15
        相关资源
        最近更新 更多