【问题标题】:Discord.py bot command issueDiscord.py 机器人命令问题
【发布时间】:2020-07-09 23:01:27
【问题描述】:

我的 Discord 机器人遇到了问题。该命令不起作用。我认为代码不是问题。除了命令之外,一切都很完美。在不和谐的情况下,如果我使用 !test mytexthere,什么也不会发生。

提前谢谢你!

 import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time
import random
from PIL import Image
token=('MyToken')

client = discord.Client()
bot = commands.Bot(command_prefix='!')

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))



@bot.command()
async def test(ctx, arg):
    await ctx.send(arg)



client.run(token)

【问题讨论】:

  • 你想要客户端还是机器人?您正在混合它们(注意您如何运行 CLIENT 但使用 BOT 修饰命令)。删除客户端并使用机器人。
  • BrainDead 的回答是正确的,您同时使用客户端和机器人。你应该摆脱client = discord.Client() 并离开机器人。然后将@client.eventclient.run(token) 都更改为@bot.eventbot.run(token)

标签: python bots discord discord.py


【解决方案1】:

我认为这里的问题是您需要将上下文传递给@bot.command,如下所示:

@bot.command(pass_context=True)

【讨论】:

猜你喜欢
  • 2021-11-29
  • 1970-01-01
  • 2021-01-01
  • 2021-10-06
  • 2022-01-10
  • 1970-01-01
  • 2021-01-21
  • 2020-10-26
  • 1970-01-01
相关资源
最近更新 更多