【发布时间】:2021-06-17 12:53:49
【问题描述】:
我试图制作一个不和谐的机器人,并试图为它创建一个命令。但机器人不响应命令。代码如下:
import discord
from discord.ext import commands
import logging
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='err.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
bot = commands.Bot(command_prefix='!')
token = 'BOT TOKEN'
GUILD = 'My test server'
prefix = bot.command_prefix
@bot.event
async def on_ready():
guild = discord.utils.get(bot.guilds, name=GUILD)
print(
f'{bot.user} is connected to the following server:\n'
f'{guild.name}(id: {guild.id})'
)
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.playing, name="minecraft"))
#here is the command where the bot is not responding to
@bot.command(name='say')
async def say(ctx, arg):
await ctx.send(arg)
bot.run(token)
任何帮助???
【问题讨论】:
-
一切正常,你真的在运行文件吗?
-
是的,输出如下:""the bot name"" is connected to the following server: My test server(id: 818450344492400710)
-
您确定机器人有权在该频道中发送消息吗?尝试添加一个
on_message函数来打印和发送用户所说的任何内容 -
它有管理员权限
-
下面的答案有效,谢谢 Aditya Tomar!
标签: python-3.x command discord.py