python - Discord bot 不响应命令
问题描述
最近,我一直在为我的朋友制作一个特定于服务器的 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')
解决方案
这是您声明机器人实例的方式,应该是这样的
在您的情况下,您正在运行客户端而不是机器人
intents = discord.Intents.default()
intents.members=True
bot = commands.Bot(command_prefix=prefix, intents=intents)
@bot.event
# code
@bot.command()
# code
bot.run('TOKEN')
推荐阅读
- sql - 根据列重复字符串 - BigQuery/SQL 标准
- java - Java Kafka流处理翻滚窗口
- sql - Excel VBA ADODB - 如何直接从 SQL 数据库中根据 excel 列值填充数据,而无需将数据复制到 Excel 工作表中
- ansible - Kerberos 在我的 ansible 设置上工作 次要代码可能会提供更多信息',851968)('在 Kerberos 数据库中找不到服务器',-1765328377))
- google-analytics - 在 Google Analytics(分析)中显示的广告系列不是我创建的?
- java - 如何在不启动应用程序的情况下在后台运行 android java 活动
- c++ - 表示 std::string 的任何 ast 类的 boost::spirit::x3 问题
- c++ - 我可以将 lambda 传递给 constexpr 构造函数吗?
- java - PATH 或 Java_Home 是否搞砸了?
- python - Flaskclassful 与 Flask-cognito