Reputation: 15
I want to make a list with a list of id discord servers that want to disable some of the functions of my bot. For example: the on_member_join method will not send a message when a person enters the server, and on the other where this function is enabled, it will send that the person has connected to the server. But I don't know how to properly store the id and use it. At the moment there is this:
async def serverid(ctx):
sid = ctx.message.guild.id
await ctx.send(sid)
sid = 705735563696799723 (id server dependent)
that's roughly what I want to get in the end
async def test(ctx):
f = open('/app/commands/servers.txt', 'r')
servers_sid = f.readlines()
now_sid = ctx.message.guild.id
if now_sid == servers_sid: #i know servers_sid = ['id'] or something similar this is what i have a problem with
await ctx.send('Command disabled')
else:
#command execution
i know servers_sid = ['id'] or something similar this is what i have a problem with
Upvotes: 0
Views: 1484
Reputation: 3426
You should use splitlines
so that you will not carry the \n
. I made the check to be not in
if it is not in the file then it will just end
async def test(ctx):
with open('/app/commands/servers.txt', 'r') as f:
servers_sid = f.read().splitlines()
now_sid = str(ctx.message.guild.id)
if now_sid not in servers_sid:
await ctx.send('Command disabled')
return
await ctx.send('This is working')
#command execution
I am assuming you txt file is like this.
123
456
789
Upvotes: 1