I am attempting to include positional arguments into an on_message function using discord.py but I receive an error below
File "/usr/lib/python3.8/site-packages/discord/client.py", line 312, in _run_event
await coro(*args, **kwargs)
TypeError: on_message() missing 3 required positional arguments: 'channels', 'textdata', and 'command'
My aim is to pass channels - a name of a channel on discord server, textdata - file path of text file, command - command that user will enter in discord channel for data to be returned.
I just wanted to ask is it possible to pass positional arguments into on_message or can message be the only one?
The code I have is
channels =[]
@client.event
async def on_message(message, channels , textdata, command):
id = client.get_guild(7319460*****229982)
if str(message.channel) in channels:
if message.content.find(command) != -1:
with open(textdata, 'r') as file:
msg = file.read(2000).strip()
while len(msg) > 0:
await message.author.send(msg)
msg = file.read(2000).strip()
def callall():
on_message(channels="boxingmma", textdata="/home/brendan/Desktop/Python/liveonsatscraper/testlasttime.txt", command="!boxingfixtures")
The reason I am attempting this is because I need to be able to run the code above on multiple discord channels, to output the data from the filepaths in textdata and to provide a different command based on the data required. I could copy the code above 100 times and input the hardcoded string values for each of the arguments but I thought it would be better to pass these values into the function above to save repeating code.
Thank you in advance to anyone that can provide guidance or a solution to this.