Discord 机器人已上线,但未在我的 Discord 频道上回复

问题描述 投票:0回答:1

我现在正在学习一个教程,我写的正是那个人所做的,但我的 $inspire 命令不起作用。

机器人获得了所有权限

import discord
import os
import requests
import json

intents = discord.Intents.default()
client = discord.Client(intents=intents)


def get_quote():
  response = requests.get("https://zenquotes.io/api/ranom")
  json_data = json.loads(response.text)
  quote = json_data[0]['q'] + " -" + json_data[0]['a']
  return (quote)


@client.event
async def on_ready():
  print('We have logged in as {0.user}'.format(client))


@client.event
async def on_message(message):
  if message.author == client.user:
    return

  if message.content.startswith('$inspire'):
    quote = get_quote()
    await message.channel.send(quote)


client.run(os.environ['TOKEN'])

代码是Python语言,我使用Replit来编码这个机器人。

我试图从 zenquotes.io 获取一条 inparation 消息,每次我在不和谐频道中输入 $inspire 时,我都期待着一个随机报价。

python discord discord.py bots
1个回答
0
投票

我在本地计算机上测试了您的代码,当我向机器人写入私人消息时它对我有用,但要在我需要的频道上工作

intents.message_content = True

intents = discord.Intents.default()
intents.message_content = True
client  = discord.Client(intents=intents)

另请参阅文档中的

Warning
命令


顺便说一句:你忘记了单词

d
中的字符
random
在网址中。

© www.soinside.com 2019 - 2024. All rights reserved.