【发布时间】: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.event和client.run(token)都更改为@bot.event和bot.run(token)
标签: python bots discord discord.py