首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@bot.command() AttributeError:“Client”对象没有“”command“”属性“”

@bot.command() AttributeError:“Client”对象没有“”command“”属性“”
EN

Stack Overflow用户
提问于 2020-05-03 23:45:41
回答 2查看 527关注 0票数 0
代码语言:javascript
复制
from discord.ext import commands
client = discord.Client(command_prefix='x!')


@client.event
async def on_ready():
    print("Successfully booted the bot up!")


@client.event
async def on_message(message):
    if message.content.find("minecraft") != -1:
        await message.channel.send('@Kerina#4436 ajde majnkraft jebemlite')


@client.command()
async def nwordpass(ctx):
    await ctx.send('Proof of you having the nword pass: https://lh3.googleusercontent.com/1HBSAiHdRdM1UVJJZlOUnMkihkiMOPPYSMTjI5WzHuvDVIBztueZR83rkUiHwIJvrfU')


client.run("NzA2MzE0MTc3NjQzNDEzNTY1.Xq4cYw.A-6MruzAgtLC1maW4VVIB2HlFM4")

为什么它不起作用?我尝试了几乎所有常见的修复方法,但没有得到任何积极的结果

EN

回答 2

Stack Overflow用户

发布于 2020-05-04 04:45:59

您需要使用discord.ext.commands中的Bot

代码语言:javascript
复制
from discord.ext import commands
client = commands.Bot(command_prefix='x!')


@client.event
async def on_ready():
    print("Successfully booted the bot up!")


@client.event
async def on_message(message):
    if message.content.find("minecraft") != -1:
        await message.channel.send('@Kerina#4436 ajde majnkraft jebemlite')
    await client.process_commands(message)


@client.command()
async def nwordpass(ctx):
    await ctx.send('Proof of you having the nword pass: https://lh3.googleusercontent.com/1HBSAiHdRdM1UVJJZlOUnMkihkiMOPPYSMTjI5WzHuvDVIBztueZR83rkUiHwIJvrfU')

我还添加了await client.process_commands(message)行,以便处理您的命令。

票数 1
EN

Stack Overflow用户

发布于 2020-05-04 00:06:27

https://discordpy.readthedocs.io/en/latest/ext/commands/extensions.html#id1上的示例代码表明正确的代码如下所示:

代码语言:javascript
复制
@commands.command()
async def nwordpass(ctx):
    await ctx.send('Proof of you having the nword pass: https://lh3.googleusercontent.com/1HBSAiHdRdM1UVJJZlOUnMkihkiMOPPYSMTjI5WzHuvDVIBztueZR83rkUiHwIJvrfU')

也就是说,command()装饰器是在commands模块上定义的,而不是在Client实例对象上定义的。

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

https://stackoverflow.com/questions/61577259

复制
相关文章

相似问题

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