我的Discord机器人不响应消息,甚至不输出到终端?

huangapple go评论92阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年2月16日 19:06:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/75471360.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定