my discord python bot isn't writing to file - python

I'm trying to write a discord bot, that when you type !create, you can type in the scores of every person and it should save the scores to a text file, but it keeps wiping the text file and I don't know why this is happening.
My Code:
import discord
client = discord.Client()
channel = client.get_channel("channelid")
file = open("TournamentScores.txt", "a")
tournament = False
scoreset1 = False
scoreset2 = False
#client.event
async def on_ready():
print("~Bot Started~")
channel = client.get_channel("channelid")
#client.event
async def on_message(message):
print("received message")
channel = client.get_channel("channelid")
global tournament, scoreset1, scoreset2
if message.content.startswith("!create") and not tournament:
print("Tournament Created")
tournament = True
await message.channel.send("Goals for Conner:")
file.write("~Tournament~ \n")
elif message.content.isdigit():
if tournament and not scoreset1:
scoreset1 = True
ConnerTemplate = "Conner - " + message.content
file.writelines(ConnerTemplate + " \n")
await message.channel.send("Goals for Ewan:")
elif scoreset1 and not scoreset2:
scoreset2 = True
EwanTemplate = "Ewan - " + message.content
file.writelines(EwanTemplate + " \n")
await message.channel.send("Goals for Jack:")
elif scoreset2 == True and tournament == True:
JackTemplate = "Jack - " + message.content
file.writelines(JackTemplate + " \n")
await message.channel.send("Goals for Thomas:")
tournament = False
elif not tournament and file == open:
ThomasTemplate = "Thomas - " + message.content
file.writelines(ThomasTemplate + " \n")
file.close()
tournament = False

Related

Python Dictionary-Bot Questions

I was making a discode dictionary bot. The function I want is for the user to enter a word and the meaning of the word through a command to the bot.
So what's been conceived!It's input (word) (meaning), but the problem is that the bot separates words and their meanings by spaces, so if the meaning gets longer, only the sentence before the space is saved as meaning.
For example, if you type !input anarchism is a~~,
When you print it out, it only outputs up to anarchism.
I think it's because there's a space between the word anarchism and is. Please look at my code and answer me how to fix it.
import discord
from discord.ext import commands
from discord.utils import get
bot = commands.Bot(command_prefix='!',intents=discord.Intents.all())
front_command = "!"
user_input = ""
user_output = ""
check_number = 0
#bot.event
async def on_ready():
print('Logging in..: ')
print(bot.user.name)
print('connection was succesful')
await bot.change_presence(status=discord.Status.online, activity=discord.Game("Testing"))
#bot.command()
async def input(ctx, arg1, arg2):
global check_number
temp_f = open("user.txt","r")
datafile = temp_f.readlines()
if len(datafile) == 0:
temp_f.close()
temp_f = open("user.txt","w")
temp_f.write(ctx.author.name + " " + str(arg1) + " " + str(arg2) +"\n")
await ctx.send("Registration completed!")
else:
for i in range(len(datafile)):
if arg1 in datafile[i]:
temp_f.close()
temp_f = open("user.txt","w")
datafile[i] = ctx.author.name + " " + str(arg1) + " " + str(arg2) +"\n"
temp_f.write('\n'.join(datafile))
await ctx.send("There is aleready "+str(arg1)+" related input, so it is changed to input now!")
check_number = 1
break
if check_number == 0:
temp_f = open("user.txt","w")
temp_f.write(ctx.author.name + " " + str(arg1) + " " + str(arg2) +"\n")
await ctx.send("Registration completed!")
check_number = 0
temp_f.close()
#bot.command()
async def output(ctx, arg1):
global check_number
temp_f = open("user.txt","r")
datafile = temp_f.readlines()
if len(datafile) == 0:
await ctx.channel.send("Nothing's registered yet! :)")
else:
for i in range(len(datafile)):
if arg1 in datafile[i]:
info = datafile[i].split()
msg = await ctx.send(str(info[2]))
await msg.reply(str(info[0]) + " " + "wrote this!")
check_number = 1
break
if check_number == 0:
await ctx.channel.send("Nothing's registered yet! :)")
check_number = 0
bot.run('Token')
I hope I understood your question correctly.
You can add a * before your last argument to get everything the User has written, like this:
#bot.command()
async def input(ctx, arg1, *, arg2):
You could also circumvent it by having the user surround the input in quotes, in your example it would be: !input anarchism "your definition here", but the method above is more user-friendly.

How do you reference a string on a different line in python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm doing some code atm which currently does a request and then goes to another channel, and edits a schedule that adds what the person requested, I am currently working to make it so you can set it up in a discord server instead of my current system (referencing specific discord channels for testing) atm the Mondaymsg string etc. aren't being found by the Monday area on my code, and I don't know what to change to get it to reference, I am an on-the-go learner coder so my code may look bad but I hope I can get some help so I can improve.
#bot.command(name='raid', pass_context=True)
async def raid(ctx, arg, arg1 = None, arg2 = None, arg3 = None,*, role_name = None):
if arg == 'setup' :
setupchannel = ctx.channel
ctx.channel.purge(amount=1)
await setupchannel.send("**=====** __**RAID SCHEDULE**__ **=====**")
Mondaymsg = await setupchannel.send("__**Monday**__")
Tuesdaymsg = await setupchannel.send("__**Tuesday**__")
Wednesdaymsg = await setupchannel.send("__**Wednesday**__")
Thursdaymsg = await setupchannel.send("__**Thursday**__")
Fridaymsg = await setupchannel.send("__**Friday**__")
Saturdaymsg = await setupchannel.send("__**Saturday**__")
Sundaymsg = await setupchannel.send("__**Sunday**__")
elif arg == 'add':
if arg1 == 'Monday':
Userping = ctx.author.mention
Message = Mondaymsg()
role = discord.utils.find(
lambda r: r.name == role_name, ctx.guild.roles)
messageContent = Mondaymsg.message.content
if arg3 in str(Mondaymsg.content):
emoji = '❌'
await ctx.message.add_reaction(emoji)
await ctx.channel.send(Userping + " Your selected time is already taken on this day, please select a different time")
else:
if role in ctx.guild.roles:
emoji = '✅'
await ctx.message.add_reaction(emoji)
await Mondaymsg.edit(content=messageContent + "\n" + Userping + " | " + f"{role.mention}" + " " + arg2 + " | " + arg3)
else:
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
elif arg1 == 'Tuesday':
channel = bot.get_channel(879538507905921125)
Userping = ctx.author.mention
role = discord.utils.find(
lambda r: r.name == role_name, ctx.guild.roles)
message = await channel.fetch_message(879568853045235773)
messageContent = message.content
if arg3 in str(message.content):
emoji = '❌'
await ctx.message.add_reaction(emoji)
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
else:
if role in ctx.guild.roles:
emoji = '✅'
await ctx.message.add_reaction(emoji)
await message.edit(content = messageContent + "\n" + Userping + " | " + f"{role.mention}" + " " + arg2 + " | " + arg3)
else:
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
elif arg1 == 'Wednesday':
channel = bot.get_channel(879538507905921125)
Userping = ctx.author.mention
role = discord.utils.find(
lambda r: r.name == role_name, ctx.guild.roles)
message = await channel.fetch_message(879569158092783667)
messageContent = message.content
if arg3 in str(message.content):
emoji = '❌'
await ctx.message.add_reaction(emoji)
await ctx.channel.send(Userping + " Your selected time is already taken on this day, please select a different time")
else:
if role in ctx.guild.roles:
emoji = '✅'
await ctx.message.add_reaction(emoji)
await message.edit(content = messageContent + "\n" + Userping + " | " + f"{role.mention}" + " " + arg2 + " | " + arg3)
else:
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
elif arg1 == 'Thursday':
channel = bot.get_channel(879538507905921125)
Userping = ctx.author.mention
role = discord.utils.find(
lambda r: r.name == role_name, ctx.guild.roles)
message = await channel.fetch_message(879569232336125972)
messageContent = message.content
if arg3 in str(message.content):
emoji = '❌'
await ctx.message.add_reaction(emoji)
await ctx.channel.send(Userping + " Your selected time is already taken on this day, please select a different time")
else:
if role in ctx.guild.roles:
emoji = '✅'
await ctx.message.add_reaction(emoji)
await message.edit(content = messageContent + "\n" + Userping + " | " + f"{role.mention}" + " " + arg2 + " | " + arg3)
else:
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
elif arg1 == 'Friday':
channel = bot.get_channel(879538507905921125)
Userping = ctx.author.mention
role = discord.utils.find(
lambda r: r.name == role_name, ctx.guild.roles)
message = await channel.fetch_message(879569295313600573)
messageContent = message.content
if arg3 in str(message.content):
emoji = '❌'
await ctx.message.add_reaction(emoji)
await ctx.channel.send(Userping + " Your selected time is already taken on this day, please select a different time")
else:
if role in ctx.guild.roles:
emoji = '✅'
await ctx.message.add_reaction(emoji)
await message.edit(content = messageContent + "\n" + Userping + " | " + f"{role.mention}" + " " + arg2 + " | " + arg3)
else:
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
elif arg1 == 'Saturday':
channel = bot.get_channel(879538507905921125)
Userping = ctx.author.mention
role = discord.utils.find(
lambda r: r.name == role_name, ctx.guild.roles)
message = await channel.fetch_message(879569379363258438)
messageContent = message.content
if arg3 in str(message.content):
emoji = '❌'
await ctx.message.add_reaction(emoji)
await ctx.channel.send(Userping + " Your selected time is already taken on this day, please select a different time")
else:
if role in ctx.guild.roles:
emoji = '✅'
await ctx.message.add_reaction(emoji)
await message.edit(content = messageContent + "\n" + Userping + " | " + f"{role.mention}" + " " + arg2 + " | " + arg3)
else:
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
elif arg1 == 'Sunday':
channel = bot.get_channel(879538507905921125)
Userping = ctx.author.mention
role = discord.utils.find(
lambda r: r.name == role_name, ctx.guild.roles)
message = await channel.fetch_message(879569473688973403)
messageContent = message.content
if arg3 in str(message.content):
emoji = '❌'
await ctx.message.add_reaction(emoji)
await ctx.channel.send(Userping + " Your selected time is already taken on this day, please select a different time")
else:
if role in ctx.guild.roles:
emoji = '✅'
await ctx.message.add_reaction(emoji)
await message.edit(content = messageContent + "\n" + Userping + " | " + f"{role.mention}" + " " + arg2 + " | " + arg3)
else:
await ctx.channel.send(Userping + " " + "I'm sorry, you need to input the name of the role you are hosting for (Example: Spectre Platoon, Diablo Squad etc.)")
else:
await ctx.channel.send("I'm sorry, your day input was invalid, please put one of the following days:\n\n"
"*Monday*\n"
"*Tuesday*\n"
"*Wednesday*\n"
"*Thursday*\n"
"*Friday*\n"
"*Saturday*\n"
"*Sunday*"
)
elif arg == 'clear':
channel = bot.get_channel(879538507905921125)
mondaymessage = await channel.fetch_message(879568766365736972)
tuesdaymessage = await channel.fetch_message(879568853045235773)
wednesdaymessage = await channel.fetch_message(879569158092783667)
thursdaymessage = await channel.fetch_message(879569232336125972)
fridaymessage = await channel.fetch_message(879569295313600573)
saturdaymessage = await channel.fetch_message(879569379363258438)
sundaymessage = await channel.fetch_message(879569473688973403)
await mondaymessage.edit(content='**__Monday__**')
await tuesdaymessage.edit(content='**__Tuesday__**')
await wednesdaymessage.edit(content='**__Wednesday__**')
await thursdaymessage.edit(content='**__Thursday__**')
await fridaymessage.edit(content='**__Friday__**')
await saturdaymessage.edit(content='**__Saturday__**')
await sundaymessage.edit(content='**__Sunday__**')
It looks like you're asking why variables defined in the first IF body aren't accessible in other IF bodies:
def func():
if some_condition:
var1 = 'blah'
var2 = 'asdf'
elseif other_condition:
# trying to access var1 or var2 here will result in a syntax error
This is because the two IF statement bodies are different scopes.
One simple option is to first define them with some default value (e.g. None) outside the function, creating global variables (in the global scope):
var1 = None
var2 = None
def func():
if some_condition:
var1 = 'blah'
var2 = 'asdf'
elif other_condition:
# now var1 and var2 are accessible here,
# but you must check or make sure they've been set
# to the values you want, meaning
# you must ensure func() has been called earlier
# with `some_condition` as true
But often defining global variables is not good practice. One alternative is to have your function accept a state variable that it modifies:
class State(object):
def __init__(self):
self.var1 = None
self.var2 = None
def func(state):
if some_condition:
state.var1 = 'blah'
state.var2 = 'asdf'
elif other_condition:
# can use state.var1 and state.var2
if __name__ == '__main__':
state = State()
# can now call func(state) to read or write state.var1 and state.var2

How to fix the no 'setup' error in cogs in discord.py?

I am getting an error :- Extension 'cogs.Funny' has no 'setup' function. but I have added the setup function so how do I fix it?
import discord
from discord.ext import commands
import random
class Funny(commands.Cog):
def __init__(self,client):
self.client = client
#commands.command()
async def rps(self,ctx):
e = discord.Embed(Title = "Rps",description = "Please react with 🪨 for rock, 🧻 for paper and ✂ for scissors",color = discord.Colour.blue())
m = await ctx.send(embed = e)
z = ['rock','scissors','paper']
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ['🪨','🧻','✂']
await m.add_reaction('🪨')
await m.add_reaction('🧻')
await m.add_reaction('✂')
try:
reaction, user = await self.client.wait_for("reaction_add", check=check)
except:
pass
else:
if str(reaction.emoji) == '🪨':
a = random.choice(z)
if a == 'rock':
new = discord.Embed(title = "Result",description = f"The bot chose {a} and u chose rock so its a tie",color = discord.Colour.purple())
await m.edit(embed = new)
elif a == 'scissors':
new = discord.Embed(title = "Result",description = f"The bot chose {a} and u chose rock so You Won!!",color = discord.Colour.green())
await m.edit(embed = new)
else:
new = discord.Embed(title = "Result",description = f"The bot chose {a} and u chose rock so You lost :(",color = discord.Colour.red())
await m.edit(embed = new)
if str(reaction.emoji) == '🧻':
a = random.choice(z)
if a == 'paper':
new = discord.Embed(title = "Result",description = f"The bot chose {a} and u chose paper so its a tie",color = discord.Colour.purple())
await m.edit(embed = new)
elif a == 'rock':
new = discord.Embed(title ="Result",description = f"The bot chose {a} and u chose paper so You Won!!",color = discord.Colour.green())
await m.edit(embed = new)
else:
new = discord.Embed(title ="Result",description = f"The bot chose {a} and u chose paper so You lost :(",color = discord.Colour.red())
await m.edit(embed = new)
if str(reaction.emoji) == '✂':
a = random.choice(z)
if a == 'scissors':
new = discord.Embed(title = "Result",description = f"The bot chose {a} and u chose scissors so its a tie",color = discord.Colour.purple())
await m.edit(embed = new)
elif a == 'paper':
new = discord.Embed(title ="Result",description = f"The bot chose {a} and u chose scissors so You Won!!",color = discord.Colour.green())
await m.edit(embed = new)
else:
new = discord.Embed(title ="Result",description = f"The bot chose {a} and u chose scissors so You lost :(",color = discord.Colour.red())
await m.edit(embed = new)
def setup(client):
client.add_cog(Funny(client))
print("fun is loaded")
Edit:- I forgot to tell how it loads it:-
extensions = [
'cogs.Funny'
]
if __name__ == "__main__":
for extension in extensions:
try:
client.load_extension(extension)
except Exception as e:
print(f"error while loading {extension}",file=sys.stderr)

Discord Bot Changing status with repl.it?

I was wondering how it is possible to get a bot status to switch
please help me because I'm new to coding discord bots and I don't know much and when I google it it doesn't work for me.
This is my code:
import keep_alive
import discord, os
from discord.ext import commands
import typing
import asyncio
import random
prefix="cs!"
client = commands.Bot(command_prefix=prefix)
def replaceSpaces(string):
string = string.strip()
i = len(string)
space_count = string.count(' ')
new_length = i + space_count * 2
if new_length > 1000:
return -1
index = new_length - 1
string = list(string)
for f in range(i - 2, new_length - 2):
string.append('0')
for j in range(i - 1, 0, -1):
if string[j] == ' ':
string[index] = '0'
string[index - 1] = '2'
string[index - 2] = '%'
index = index - 3
else:
string[index] = string[j]
index -= 1
return ''.join(string)
#client.event
async def on_ready():
await client.change_presence(activity=discord.Game(name="cs!help || made with <3 by Spoon#7194"))
#client.event
async def on_ready():
servers = len(client.guilds)
members = 0
for guild in client.guilds:
members += guild.member_count - 1
await client.change_presence(activity = discord.Activity(
type = discord.ActivityType.watching,
name = f'cs!help | {servers} Server {members} Member'
))
#client.event
async def on_message(message):
msg = message.content.lower()
if message.author == client.user:
return
elif msg.startswith("cs!hello"):
await message.channel.send(f"hello, {message.author}!")
elif msg.startswith("cs!help"):
await message.channel.send(f"commands: cs!hello, cs!replsearch <query>, cs!twitch <query>, cs!youtube <query>, cs!google <query>")
elif msg.startswith("cs!replsearch "):
resultr = msg.split('cs!replsearch ', 1)
if resultr[-1] == "":
await message.channel.send("Error :face_with_raised_eyebrow:, no query given")
elif msg.startswith("cs!replsearch"):
await message.channel.send("Error :face_with_raised_eyebrow:, no query given")
elif msg.startswith("cs!twitch "):
resultt = msg.split('cs!twitch ', 1)
if resultt[-1] == "":
await message.channel.send("Error :face_with_raised_eyebrow:, no query given")
else:
await message.channel.send(f"https://twitch.tv/search?term={replaceSpaces(resultt[-1])}")
elif msg.startswith("cs!twitch"):
await message.channel.send("Error :face_with_raised_eyebrow:, no query given")
elif msg.startswith("cs!youtube "):
resulty = msg.split('cs!youtube ', 1)
if resulty[-1] == "":
await message.channel.send("Error :face_with_raised_eyebrow:, no query given")
else:
await message.channel.send(f"https://www.youtube.com/results?search_query={replaceSpaces(resulty[-1])}")
elif msg.startswith("cs!youtube"):
await message.channel.send("Error :face_with_raised_eyebrow:, no query given")
elif msg.startswith("cs!google "):
result = msg.split('cs!google ', 1)
if result[-1] == "":
await message.channel.send("Error :face_with_raised_eyebrow:, no query given")
else:
await message.channel.send(f"https://www.google.com/search?q={replaceSpaces(result[-1])}")
elif msg.startswith("cs!google"):
await message.channel.send("Error :face_with_raised_eyebrow:, no query given")
elif msg.startswith("cs!"):
await message.channel.send("Error :face_with_raised_eyebrow:, not a valid command")
#server.server()#bot.command()
#async def token
#embed=discord.Embed(title="Help", description="description here")
#embed.add_field(name="Moderation commands", value="your commands here", inline=False)
#embed.add_field(name="Fun Commands", value="your commands here", inline=False)
#embed.set_footer(text="footer text")
#await ctx.send(embed=embed)
keep_alive.keep_alive()
client.run('{I deleted this part here}')
Change Your Status every x seconds
#discord.ext.tasks.loop(seconds=5)
async def change_p():
await client.wait_until_ready()
statuses = [f"{len(client.guilds)} Servers with {len(client.users)} Users!", "You Talk!",
"The Epic Server!"]
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=choice(statuses)))
change_p.start()
const status = "YOURSTATUS"
client.user.setActivity(status)
Also Try that :)

Why does my mod-mail not work, but deleting messages work in discord.py Python Programming?

I'm having some trouble figuring out why one part of my code works, but the other part does not. Both pieces of code work perfectly separately, however, when put in the same file, only one will work.
I'm making a Discord Bot with discord.py, one part of the code (The top part) is supposed to be mod-mail, taking a message you DM the bot and then relaying it to a channel in the server. Then a moderator, for example, can reply the person by taking their user ID and pinging them with <#userid> , then, the bot will take that message and send it to the person who DMed the bot. <-- This part of the code doesn't work
The 2nd part of my file basically monitors a channel called img-only and deletes any message that does not have an empty string, which means no message that isn't an image/file can be sent without being deleted. <-- This function works, it deletes any string in the img-only channel
Here's my code:
import discord
client = discord.Client()
#mod-mail
#client.event
async def on_message(message):
empty_array = []
modmail_channnel = discord.utils.get(client.get_all_channels(), name = "mod-mail")
if message.author == client.user:
return
if str(message.channel.type) == "private":
if message.attachments != empty_array:
files = message.attachments
await modmail_channnel.send("[" + message.author.display_name + "] ")
for file in files:
await modmail_channnel.send(file.url)
else:
await modmail_channnel.send("[" + message.author.display_name + "] " + message.content)
elif str(message.channel) == "mod-mail" and message.content.startswith("<"):
member_object = message.mentions[0]
if message.attachments != empty_array:
files = message.attachments
await member_object.send("[" + message.author.display_name + "] ")
for file in files:
await member_object.send(file.url)
else:
index = message.content.index(" ")
string = message.content
mod_message = string[index:]
await member_object.send("[" + message.author.display_name + "] " + mod_message)
#img-only moderation
#client.event
async def on_message(message):
if str(message.channel) == "img-only" and message.content != "":
await message.channel.purge(limit=1)
client.run('Bot Token')
I use Python 3.8.5, Discord.py 1.4.1, Visual Studio Code is my code editor
Thank you :)
First things first, you can only have one on_message using a Client instance; Since you have more than one, only the last on_message will be called. One way of fixing this is by combining both of your on_message events together into one on_message
#client.event
async def on_message(message):
# Mod-mail
empty_array = []
modmail_channnel = discord.utils.get(client.get_all_channels(), name="mod-mail")
if message.author == client.user:
return
if str(message.channel.type) == "private":
if message.attachments != empty_array:
files = message.attachments
await modmail_channnel.send("[" + message.author.display_name + "] ")
for file in files:
await modmail_channnel.send(file.url)
else:
await modmail_channnel.send("[" + message.author.display_name + "] " + message.content)
elif str(message.channel) == "mod-mail" and message.content.startswith("<"):
member_object = message.mentions[0]
if message.attachments != empty_array:
files = message.attachments
await member_object.send("[" + message.author.display_name + "] ")
for file in files:
await member_object.send(file.url)
else:
index = message.content.index(" ")
string = message.content
mod_message = string[index:]
await member_object.send("[" + message.author.display_name + "] " + mod_message)
# img-only moderation
if str(message.channel) == "img-only" and message.content != "":
await message.channel.purge(limit=1)
Another way is switching to a Bot instance and using listeners. In the example below the img-only moderation is a listener to your main on_message
import discord
from discord.ext import commands
client = commands.Bot(command_prefix='.')
#client.event
async def on_message(message):
# Mod-mail
empty_array = []
modmail_channnel = discord.utils.get(client.get_all_channels(), name="mod-mail")
if message.author == client.user:
return
if str(message.channel.type) == "private":
if message.attachments != empty_array:
files = message.attachments
await modmail_channnel.send("[" + message.author.display_name + "] ")
for file in files:
await modmail_channnel.send(file.url)
else:
await modmail_channnel.send("[" + message.author.display_name + "] " + message.content)
elif str(message.channel) == "mod-mail" and message.content.startswith("<"):
member_object = message.mentions[0]
if message.attachments != empty_array:
files = message.attachments
await member_object.send("[" + message.author.display_name + "] ")
for file in files:
await member_object.send(file.url)
else:
index = message.content.index(" ")
string = message.content
mod_message = string[index:]
await member_object.send("[" + message.author.display_name + "] " + mod_message)
await client.process_commands(message)
# img-only moderation
#client.listen()
async def on_message(message):
if str(message.channel) == "img-only" and message.content != "":
await message.channel.purge(limit=1)

Categories

Resources