简体   繁体   English

使用夸脱 python 运行 discord 机器人

[英]Running discord bot using quart python

I am trying to create a discord bot with two features.我正在尝试创建一个具有两个功能的 discord 机器人。

  1. To update everyone in the server about some info (this is done by using webhook and a uptimerobot to call the webhook)向服务器中的每个人更新一些信息(这是通过使用 webhook 和 uptimerobot 调用 webhook 来完成的)
  2. Community in the server can prompt the bot to provide additional info by telling the bot the ID of.服务器中的社区可以通过告诉机器人 ID 来提示机器人提供附加信息。

I am using app.route for the first feature and on_message() as the second one.我将 app.route 用于第一个功能,将 on_message() 用作第二个功能。 But only the first one is working.但只有第一个有效。

This is the snippet of my code这是我的代码片段

 import discord import asyncio import os from quart import Quart from discord.ext import commands from dotenv import load_dotenv import requests import datetime from datetime import timezone import json import random import nest_asyncio load_dotenv() TOKEN = os.getenv('DISCORD_TOKEN') OS_TOKEN = os.getenv('OPENSEA_TOKEN') nest_asyncio.apply() app = Quart(__name__) client = discord.Client() @app.before_serving async def before_serving(): loop = asyncio.get_event_loop() await client.login(TOKEN) loop.create_task(client.connect()) @client.event async def on_message(message): if message.author == client.user: return print('in func') @client.event async def on_ready(): print("Initiated.") @app:route("/send") async def broadcast(). for server in client:guilds. for channel in server:text_channels: try. await channel:send("test") except Exception: continue else. break return "hello world" app.run()

I managed to run both separately.我设法分别运行两者。 But when I run them together, only the webhook is working and any @client modules are not working.但是当我一起运行它们时,只有 webhook 正在工作,而任何 @client 模块都不起作用。 Also I migrated from flask to quart because I read somewhere that flask can not run both itself and discord server.此外,我从 flask 迁移到 quart,因为我在某处读到 flask 不能同时运行自身和 discord 服务器。

Any help would be appreciated!任何帮助,将不胜感激!

I think u might have forgotten to check the needed permissions in the discord dev portal.我想你可能忘记在 discord 开发门户中检查所需的权限。 and also I solved my somehow similar problem by replacing @client.event(s) with @bot.event而且我通过用@bot.event 替换@client.event(s) 解决了我的类似问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM