我想做一个不和谐的机器人,然后它一直显示在不和谐包中找不到客户端。我安装了错误的不和谐包吗?
# TOKEN and CHANNEL redacted
import discord
client = discord.Client()
@client.event
async def msg():
general = client.get_channel(CHANNEL)
await general.send('HELLO')
client.run(TOKEN)
运行时错误:
Traceback (most recent call last):
File "C:/Users/user/Desktop/dis.py", line 1, in <module>
import discord
File "C:\Users\user\Desktop\venv\lib\site-packages\discord\__init__.py", line 25, in <module>
from .client import Client
File "C:\Users\user\Desktop\venv\lib\site-packages\discord\client.py", line 27, in <module>
import asyncio
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\asyncio\__init__.py", line 8, in <module>
from .base_events import *
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 39, in <module>
from . import coroutines
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\asyncio\coroutines.py", line 5, in <module>
import inspect
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\inspect.py", line 35, in <module>
import dis
File "C:\Users\user\Desktop\dis.py", line 3, in <module>
client = discord.Client()
AttributeError: partially initialized module 'discord' has no attribute 'Client' (most likely due to a circular import)
Process finished with exit code 1
答案 0 :(得分:0)
A:立即删除您的 BOT 代币 OH GOD OH S***
乙:
most likely due to a circular import
确保您没有在任何其他导入(如果存在)中再次导入 dicord
并确保您的文件未命名为 discord.py
答案 1 :(得分:0)
好的,试试这个:
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = "Your prefix")
@client.event
async def on_ready():
general = client.get_channel(CHANNEL)
await general.send('HELLO')
如果有什么问题,请告诉我。但是,我不知道您在 @client.event 下的代码是否有效。我还没有测试出来。希望这有帮助:) 再说一遍:如果有什么问题,请告诉我。
答案 2 :(得分:0)
首先,您需要添加导入!
import discord
from discord.ext import commands
其次你需要添加你的前缀
client = commands.Bot(command_prefix = "Your prefix")
修复你的命令
@client.command()
async def msg(ctx):
await ctx.send("HELLO")
然后当然添加您的令牌! 完整代码:
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = "Your prefix")
@client.event
async def hi(ctx):
await ctx.send("HELLO")
我将您的 on_ready 命令设置为一个命令,因为如果您在多个服务器上拥有该机器人,您将立即被禁止使用 discord api!
答案 3 :(得分:0)
假设您想通过直接消息向用户发送消息,这个简单的代码就是您的答案。 您可以通过键入 --msg @(Username) (Message) 向某人发送消息
def remove_punctuations(text):
for punctuation in string.punctuation:
text = text.replace(punctuation, '')
return text
# Apply to the DF series
df['new_column'] = df['column'].apply(remove_punctuations)
P.S 我添加了一个嵌入,因为它看起来很酷,但你可以删除它。
答案 4 :(得分:0)
discord.Client() 不是函数。像这样定义客户端:
import discord
from discord.ext import commands
您需要使用 Intent 来访问一些函数,例如:on_member_join 和 on_member_remove
intents = discord.Intents.all()
client = commands.Bot(command_prefix="!", intents=intents, owner_id=putyouridhere)
@client.event
async def on_ready():
print("Bot is ready.")
general = client.get_channel(CHANNEL)
await general.send('HELLO')
client.run("TOKEN")
答案 5 :(得分:-1)
这里的问题似乎是您使用错误的包来获取客户端。
要解决这个问题
import discord
from discord.ext import commands
client = commands.Bot(command_prefix='prefix you want')
希望对你有帮助
答案 6 :(得分:-1)
下载并安装 pip (https://pypi.org/project/pip/) 您可以使用 get-pip.py (https://bootstrap.pypa.io/get-pip.py) 复制所有内容并粘贴到 .py 文件中并运行它 在该类型之后: pip install discord(在 cmd 或终端中)