英文:
My Discord bot is not responding to messages/not even outputting to terminal?
问题
尝试创建一个有点复杂的机器人,但在开始编写其他代码之前,我想确保机器人在Discord中工作,并能响应基本命令 - 当有人使用命令“!hello”时发送消息“Hello”。
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix='!', intents=intents)
TOKEN = "TOKEN"
@bot.event
async def on_ready():
print(f'Bot connected as {bot.user}')
@bot.command(name='hello')
async def dosomething(ctx):
print('Hello command made')
await ctx.send("Hello!")
bot.run(TOKEN)
on_ready 函数确实能够工作,它在连接时输出机器人的名称,但尝试让它响应简单的 !hello 命令时什么都不会发生,它既不在频道中发送消息,也不在控制台中打印信息。这是来自Discord Developer Portal的机器人权限:https://i.stack.imgur.com/abkjP.jpg
英文:
Trying to make a sorta complicated bot, but before i get started on writing the other code I wanted to just make sure that the bot worked in Discord, and was up and running and responding to a basic command - Send the message "Hello" when someone used the command "!hello".
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix='!', intents=intents)
TOKEN = "TOKEN"
@bot.event
async def on_ready():
print(f'Bot connected as {bot.user}')
@bot.command(name='hello')
async def dosomething(ctx):
print(f'Hello command made')
await ctx.send("Hello!")
bot.run(TOKEN)
the on_ready function does work, it outputs the name of the bot whenever it connects, but trying to get it to respond to a simple !hello command does nothing, it doesnt message in the channel and it doesn't print to console. Here's my permissions for the bot as well from Discord Developer Portal - https://i.stack.imgur.com/abkjP.jpg
答案1
得分: 0
在commands.Bot
上面的行添加以下内容:
intents.message_content = True
英文:
Try adding this at the line above commands.Bot
intents.message_content = True
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论