请记住,我是Python的新手,也是discord的新手。我正在尝试使用Python创建一个ChatBot,我有一个命令,你必须说出来才能让机器人和你说话。该命令称为talk。要停止与机器人的对话,您必须启用stoptalk。遗憾的是,我编写的启用stop talk的函数不起作用,我不知道如何修复它。请帮帮忙。
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time
Client = discord.Client()
client = commands.Bot(command_prefix = ":")
on_talk = False
@client.event
async def on_ready():
print("You can talk to me now!")
@client.command(pass_context=True)
async def ontalker(message):
global on_talk
if message.content.upper().startswith(":TALK"):
on_talk = True
@client.command(pass_context=True)
async def offtalker(message):
global ontalk
if message.content.upper().startswith(":STOPTALK"):
on_talk = False
@client.command(pass_context=True)
async def stoptalk(ctx):
print("on_talk is False.")
@client.command(pass_context=True)
async def talk(ctx):
@client.event
# Everything I want to do goes here
发布于 2018-07-30 06:12:05
您的offtalker()
函数中有一个拼写错误。你写道:
global ontalk
但是,您尝试修改的全局变量是on_talk
,因此该变量仅在函数的局部作用域中更改为False
。相反,可以这样写:
global on_talk
https://stackoverflow.com/questions/51584954
复制相似问题