我正在尝试创建一个使用 asyncio 的不和谐机器人。我不懂大部分语法,比如@的使用或异步本身,所以请原谅我的无知。我不知道如何在谷歌中表达这个问题。
import discord
from discord.ext.commands import Bot
from discord.ext import commands
Client = discord.Client()
bot_prefix = "&&"
client = commands.Bot(command_prefix=bot_prefix)
@client.event
async def on_ready():
print("Bot online")
print("Name:", client.user.name)
print("ID:", client.user.id)
@client.command(pass_context=True)
async def ToggleSwitch(ctx):
theSwitch = not theSwitch
@client.event
async def on_message(message):
await client.process_commands(message)
if message.author.id == "xxxxx" and theSwitch == True:
await client.send_message(message.channel, "Switch is on and xxxxx said something")
我稍微过分简化了这个问题,但我想了解的是如何将theSwitch
变量从ToggleSwitch
函数传递on_message
给外部数据库?)。
再次抱歉,我很抱歉,但我真的很想解决这个问题,因为我真的受到这个问题的影响。