Python 如何在多台服务器上运行命令,而不在一台服务器上停止命令,并在discord.py的每台服务器上停止整个命令
所以问题是,代码运行得很好,但是如果我在多个服务器上运行spam命令,但是在一个服务器上停止它,那么它就会停止在所有服务器上发送垃圾邮件。我不想那样。有没有办法解决这个问题Python 如何在多台服务器上运行命令,而不在一台服务器上停止命令,并在discord.py的每台服务器上停止整个命令,python,discord.py,Python,Discord.py,所以问题是,代码运行得很好,但是如果我在多个服务器上运行spam命令,但是在一个服务器上停止它,那么它就会停止在所有服务器上发送垃圾邮件。我不想那样。有没有办法解决这个问题 import discord, pyautogui, time from discord.ext import commands client = commands.Bot(command_prefix = '.') @client.event async def on_ready(): print('We h
import discord, pyautogui, time
from discord.ext import commands
client = commands.Bot(command_prefix = '.')
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.command()
@commands.has_role('discordpy')
async def spam(ctx, *, my_id):
print("it worked")
time.sleep(5)
x = 1
global y
y = 0
while y != 1:
@client.event
async def on_message(message):
if message.content == ".stop":
y = 1
await client.process_commands(message)
myid = str(my_id)
await ctx.channel.send(myid + " x " +str(x))
print(x)
x += 1
print(y)
time.sleep(0.5)
client.run('<Token>')
import discord,pyautogui,time
从discord.ext导入命令
client=commands.Bot(命令前缀='。)
@客户端事件
_ready()上的异步定义:
打印('我们已以{0.user}的身份登录。格式(客户端))
@client.command()
@commands.has_角色('discordpy'))
异步定义垃圾邮件(ctx,*,我的id):
打印(“它工作了”)
时间。睡眠(5)
x=1
全局y
y=0
而y!=1:
@客户端事件
异步def on_消息(消息):
如果message.content==“.stop”:
y=1
等待客户端处理命令(消息)
myid=str(myu-id)
等待ctx.channel.send(myid+“x”+str(x))
打印(x)
x+=1
打印(y)
睡眠时间(0.5)
client.run(“”)
正如您所知,我已经尝试使用新命令来停止第一个命令,但没有任何效果我建议您将服务器id和垃圾邮件命令的状态(无论是否打开)存储在SQL数据库中,因此,您可以将数据库中的id与刚刚调用该命令的服务器的id进行比较,并检查该服务器的spam命令的状态是否为on 如果这被证明太难,至少用同样的原则创建一本词典 DICT示例(不推荐,尤其是大量服务器): 确保首先将其声明为全局
global statuses
statuses
你所描述的问题是,脚本的最佳功能是什么。也许吧,但我不需要它,至少在这种情况下不需要。如果可以,请帮助我当我尝试运行它时,它会说“NameError:name'value'未定义”,因此如果您能提供完整的代码以及我提供的内容,这将非常有用,但非常感谢。您是否有意见分歧?是的,或多或少@justjude#2096
# Checking the statuses
value = statuses[message.guild.id]
if value == "on":
# Do stuff
else:
# Don't do stuff
global statuses
statuses