I know that whenever i use from my_file_contains_data.py import data_i_want
i can access the data i want and i can use it for ‘if’ statements.
but in ‘my_file_contains_data.py’ file, the ‘data_i_want’ is a variable that can changes.
and when the ‘data_i_want’ changes, it does not change in the main file i work, it always stays the same value in the beginning.
Here is my codes:
main file:
from cmds.channelproctection import curstat
@bot.event
async def on_guild_channel_delete(channel):
if channel.guild.id == my_guild_id and curstat==1:
memberRole = channel.guild.get_role(693197190377766931) # Server's Default Member Role ID.
async for entry in channel.guild.audit_logs(limit=1, action=discord.AuditLogAction.channel_delete):
if not entry.user.id == 472911936951156740:
try:
await entry.user.edit(nick='I hate my Mom.', roles=[memberRole], reason='Deleting a Channel.')
await channel.clone(reason=f'Channel re-opened because {entry.user.name} deleted the channel.')
chan2=bot.get_channel(my_announcement_channel)
await chan2.send(f"@everyone, {entry.user.mention}, deleted **{channel.name}** channel. He hates his mom.")
except Forbidden:
ownerid = bot.get_user(owners[0])
chan = await ownerid.create_dm()
chan3 = await bot.get_user(my_friends_id).create_dm()
await channel.clone(reason=f"@everyone, {entry.user.mention}, deleted **{channel.name}** channel. He hates his mom.")
await chan.send(f"{entry.user.name}, removed {channel.name}.")
await chan3.send(f"{entry.user.name}, removed {channel.name} ")
elif channel.guild.id == my_guild_id and curstat==0:
async for entry in channel.guild.audit_logs(limit=1, action=discord.AuditLogAction.channel_delete):
if not entry.user.id == 472911936951156740: # VoiceMaster ID
ownerid = bot.get_user(owners[0])
chan = await ownerid.create_dm()
await chan.send(f"Channel protection is off but {entry.user.name}, removed {channel.name}!")
elif channel.guild.id == IEEM and curstat not in [0, 1]:
print('there is a huge problem!')
await bot.close()
channel-protection (a.k.a ‘my_file_contains_data’):
curstat=1
@commands.command(aliases = ["chanprot", 'chapro',"sex"],hidden=True)
@commands.has_guild_permissions(administrator=True)
async def channelprotection(ctx, state : str):
global curstat
if state in ["open", "turnon", "on", '1']:
if not curstat==1:
curstat = 1
await ctx.message.add_reaction("✅")
await ctx.send("Channel protection is on!",reference=ctx.message, mention_author=False)
else:
await ctx.message.add_reaction("🖕🏻")
await ctx.send("Already On.")
elif state in ['close', 'turnoff', 'off', '0']:
if not curstat==0:
curstat = 0
await ctx.message.add_reaction("✅")
await ctx.send("Caution, Channel protection is disabled!",reference=ctx.message, mention_author=False)
else:
await ctx.message.add_reaction("🖕🏻")
await ctx.send("Already Off.")
else:
await ctx.send("Use open for turning on, use close for turning of.")
async def setup(bot):
bot.add_command(channelprotection)
When i used turn off command, it gives me a reply but ‘curstat’ variable doesn’t changes so bot still recreates channels when i or someone trys to remove a channel. i tried adding the line from cmds.channelproctection import curstat
after event handlers and define function
like this:
@bot.event
async def on_guild_channel_delete(channel):
from cmds.channelprotection import curstat
if channel.guild.id == 693193721612861511 and curstat==1:
...
it worked but i dont think this usage is correct. is this true, did i solve my problem or is there a good and logical way to ‘fix’ this issue?