【发布时间】: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