【问题标题】:Discord bot does no respond to commandDiscord bot 不响应命令
【发布时间】:2021-08-28 12:56:39
【问题描述】:

最近,我一直在为我的朋友制作一个特定于服务器的 Discord 机器人。当我了解到 Discord API 可以使用前缀和命令事件而不是属性 startswith 时,我很快就开始更改我的整个代码。我保留了我的机器人的响应,但将其更改为在 @bot.command 上运行。尽管指定了我的前缀和命令,但机器人没有响应我或服务器上的任何其他人。我自动假设它是表情符号的前缀,但将其更改为“!”或“$”也不起作用。有谁知道为什么?

import discord
from discord.ext import commands
from dotenv import load_dotenv
from discord.ext.commands import Bot
import os
import json
import random
import requests

#welcome channel="852346049959821312"
client = discord.Client()
intents = discord.Intents.default()
intents.members=True
client = discord.Client(intents=intents)
bot = commands.Bot(command_prefix="<:givebanana:852295575772856400>")

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))
    global points
    try:
        with open('data.txt') as f:
            points = json.load(f)
    except FileNotFoundError:
        print("Could not load data.json")
        points = {}

@client.event
async def on_member_join(member):
    embed=discord.Embed(title="Welcome",description="Be sure to change your status. Once that is done, you will be assigned the monke intern role. Why don't you say hello to our new monke, <@&852658353678319656>. Viva la monke!", color=discord.Color.from_rgb(0,128,0))
    embed.set_thumbnail(url=member.avatar_url)
    channel = client.get_channel(852677413367709706)
    await channel.send(f"{member.mention}", embed=embed)

@bot.command()
async def roles(ctx):
    embed=discord.Embed(title="Monke Roles",description="The more people DM you 'monke', the more points you earn.", color=discord.Color.from_rgb(255,255,53))
    embed.set_thumbnail(url="http://www.clker.com/cliparts/f/1/e/9/H/i/banana-md.png")
    embed.add_field(name="Points",value="Someone DMs you and joins the server= 2 points\n\nSomeone DMs you but doesn't join= 1 point\n",inline=False)
    embed.add_field(name="???? Monke Employee",value="1 Point", inline=True)
    embed.add_field(name="???? Monke Soldier",value="5 Points",inline=True)
    embed.add_field(name="???? Monke Officer",value="10 Points",inline=True)
    embed.add_field(name="????️ Monke General",value="20 Points",inline=True)
    embed.add_field(name="???? Monke Mayor",value="30 Points",inline=True)
    embed.add_field(name="????️ Monke Govenor",value="50 Points",inline=True)
    embed.add_field(name="????️ Monke President",value="100 Points",inline=True)
    await ctx.send(ctx.author.mention,embed=embed)
    print('Command Sucessful')

@bot.command()
async def ping(ctx):
    await ctx.send('_**AH AH**_  Here!')

client.run('censoredtoken')

【问题讨论】:

  • 请在您的需求中更加准确:您到底想要实现什么? “什么都没有发生”是什么意思?您对代码进行了哪些测试?到目前为止,您尝试了什么?
  • 我编辑了我的问题,现在我的研究和“错误”更加具体。

标签: python command discord.py


【解决方案1】:

这是你声明你的机器人实例的方式,应该是这样的

在您的情况下,您运行的是客户端而不是机器人

intents = discord.Intents.default()
intents.members=True
bot = commands.Bot(command_prefix=prefix, intents=intents)


@bot.event
# code 

@bot.command()
# code 

bot.run('TOKEN')

【讨论】:

  • 我现在更接近一点,但“bot.run”似乎给了我一个错误?还有什么我应该添加到我的代码中的吗?
  • 错误 503,来自我在日志中找到的内容。
猜你喜欢
  • 2020-12-15
  • 2021-02-17
  • 2023-03-09
  • 2021-04-17
  • 2022-10-23
  • 2021-10-23
  • 2022-01-04
相关资源
最近更新 更多