我试着用discord.py做了一个机器人
bot = commands.Bot(command_prefix='$', description="This is a test bot")
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
@bot.command(name='ping')
async def ping(ctx):
await ctx.send("pong")当我告诉它时,它不会发送消息。我使用的是discord.py 1.7.3和Python3.9.4,控制台显示它已连接,但除了显示为在线之外,它不会做任何其他事情。我说过了
$ping

完整代码:
import os
import discord
from dotenv import load_dotenv
from discord.ext import commands
# load token (dont share pls)
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
# Is this better?
bot = commands.Bot(command_prefix='$', description="This is a test bot")
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
# commands here
@bot.command(name='ping')
async def ping(ctx):
await ctx.send("pong")
@bot.command()
async def test(ctx, *args):
await ctx.send('{} arguments: {}'.format(len(args), ', '.join(args)))
client.run(TOKEN)发布于 2021-06-30 21:31:01
你不能同时运行discord.Client和commands.Bot
由于Bot与Client相同,但有一些额外的功能,因此您应该使用Bot
删除:client = discord.Client()
更改:@client.event更改为@bot.event,client.run()更改为bot.run()
https://stackoverflow.com/questions/68195265
复制相似问题