【问题标题】:Discord command bot doesn't responde (python)Discord 命令机器人不响应(python)
【发布时间】:2021-07-22 15:26:23
【问题描述】:

我的 discord 机器人有问题:当我输入 discord $ping 时,他没有回复我 pong 并且我不知道为什么,我只是检查机器人是否具有管理员角色,以便他可以写,我'我使用 VsCode,他没有给我任何错误。
这是代码

import discord
from discord.ext import commands
import requests
import json
import random

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

@bot.command()
async def ping(ctx):
    await ctx.channel.send("pong")

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

client.run("XXXXXXXXXXXXXXXXXXXXXXX")

【问题讨论】:

  • 你在混合clientbot,不要那样做...这就是命令不起作用的原因。
  • 那么我需要删除什么? client =discord.Client() andall@client 事件?
  • 是的,您可以删除client = discord.Client() 并使用bot.eventbot.command()。要运行机器人,请使用bot.run("Token")

标签: python command discord.py bots


【解决方案1】:

问题是,您使用bot.command 定义命令,但您只使用client.run。要解决此问题,请选择客户端或机器人,但不能同时选择两者,例如,如果您选择机器人,则如下所示:

import discord
from discord.ext import commands
import json
import random

bot = commands.Bot(command_prefix='$')

@bot.command()
async def ping(ctx):
    await ctx.channel.send("pong")

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

也不要使用请求,因为它会阻塞。

【讨论】:

  • @Luigi2201 如果它对您有用,您能否接受答案(带有绿色复选标记),以便其他人可以快速看到它有效?
  • 我现在就做
猜你喜欢
  • 2021-03-11
  • 2021-09-04
  • 2022-10-24
  • 2021-03-17
  • 2020-11-27
  • 2023-02-10
  • 2022-12-15
  • 2021-02-17
相关资源
最近更新 更多