首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么discord.py discord.ext.commands不起作用?

为什么discord.py discord.ext.commands不起作用?
EN

Stack Overflow用户
提问于 2021-06-30 20:59:18
回答 1查看 261关注 0票数 0

我试着用discord.py做了一个机器人

代码语言:javascript
复制
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,控制台显示它已连接,但除了显示为在线之外,它不会做任何其他事情。我说过了

代码语言:javascript
复制
$ping

完整代码:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2021-06-30 21:31:01

你不能同时运行discord.Clientcommands.Bot

由于Bot与Client相同,但有一些额外的功能,因此您应该使用Bot

删除:client = discord.Client()

更改:@client.event更改为@bot.eventclient.run()更改为bot.run()

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68195265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档