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")
为什么不起作用? 我尝试了几乎所有常见的修复方法,但是都没有得到任何积极的结果
答案 0 :(得分:1)
您需要使用Bot
中的discord.ext.commands
类
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 :(得分:-1)
https://discordpy.readthedocs.io/en/latest/ext/commands/extensions.html#id1处的示例代码表明正确的代码应如下所示:
@commands.command()
async def nwordpass(ctx):
await ctx.send('Proof of you having the nword pass: https://lh3.googleusercontent.com/1HBSAiHdRdM1UVJJZlOUnMkihkiMOPPYSMTjI5WzHuvDVIBztueZR83rkUiHwIJvrfU')
也就是说,command()
装饰器是在commands
模块上定义的,而不是在Client
实例对象上定义的。