Discord bot 不响应命令

时间:2021-06-11 15:07:59

标签: python command discord.py

最近,我一直在为我的朋友制作一个特定于服务器的 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')

1 个答案:

答案 0 :(得分:0)

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

就您而言,您运行的是客户端而不是机器人

import io 

buf = io.BytesIO()
plt.savefig(buf, format="jpg")
#print(buf.getvalue()) return bytes of plot 

fp = tempfile.NamedTemporaryFile() 

# print(fp.name) return file name 

with open(f"{fp.name}.jpg",'wb') as ff:
    ff.write(buf.getvalue()) 

buf.close()