JavaScript
x
138
138
1
def sb(loop):
2
asyncio.set_event_loop(loop)
3
4
token = e.get()
5
6
7
client = commands.Bot(command_prefix="=", help_command=None, self_bot=True)
8
9
@client.command(pass_context=True)
10
async def purge(ctx,amount):
11
if ctx.message.author.id == client.user.id:
12
await ctx.message.delete()
13
async for message in ctx.message.channel.history(limit=int(amount)).filter(lambda m: m.author == client.user).map(
14
lambda m: m):
15
try:
16
await message.delete()
17
await asyncio.sleep(0.7)
18
except:
19
pass
20
21
@client.command(pass_context=True)
22
async def av(ctx, user: discord.Member):
23
await ctx.message.delete()
24
if client.user.id == ctx.message.author.id:
25
u = user.avatar_url
26
await ctx.send(u)
27
28
@client.command()
29
async def stealpfp(ctx, user:discord.Member):
30
await ctx.message.delete()
31
password = "chidubem04"
32
with open("pfp/Stolen.png", "wb") as f:
33
r = requests.get(user.avatar_url, stream=True)
34
for block in r.iter_content(1024):
35
if not block:
36
break
37
f.write(block)
38
39
Image.open("pfp/Stolen.png").convert("RGB")
40
with open("pfp/Stolen.png", "rb") as f:
41
await client.user.edit(password=password, avatar=f.read())
42
43
@client.command()
44
async def prayer(ctx):
45
await ctx.message.delete()
46
await ctx.send("Our Father in heaven, hallowed be your name, your kingdom come, your will be done,on earth as in heaven. Give us today our daily bread. Forgive us our sins as we forgive those who sin against us. Lead us not into temptation but deliver us from evil. For the kingdom, the power, and the glory are yours now and for ever. Amen.")
47
48
49
50
51
@client.command()
52
async def time(ctx, zone):
53
await ctx.message.delete()
54
if zone == "pacific".lower():
55
time = timezone("US/Pacific")
56
sa_time = datetime.now(time)
57
await ctx.send(sa_time.strftime("%H:%M"))
58
elif zone == "eastern".lower():
59
time = timezone("US/Eastern")
60
sa_time = datetime.now(time)
61
await ctx.send(sa_time.strftime("%H:%M"))
62
elif zone == "mountain".lower():
63
time = timezone("US/Mountain")
64
sa_time = datetime.now(time)
65
await ctx.send(sa_time.strftime("%H:%M"))
66
elif zone == "central".lower():
67
time = timezone("US/Central")
68
sa_time = datetime.now(time)
69
await ctx.send(sa_time.strftime("%H:%M"))
70
71
@client.command()
72
async def ip(ctx, name):
73
await ctx.message.delete()
74
ip = socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff)))
75
await ctx.send(socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff))))
76
77
@client.command()
78
async def destroy(ctx): # b'xfc'
79
await ctx.message.delete()
80
for channel in list(ctx.guild.channels):
81
try:
82
await channel.delete()
83
except:
84
pass
85
for user in list(ctx.guild.members):
86
try:
87
await user.ban()
88
except:
89
pass
90
for role in list(ctx.guild.roles):
91
try:
92
await role.delete()
93
except:
94
pass
95
96
@client.command()
97
async def streaming(ctx,*,name):
98
await ctx.message.delete()
99
await client.change_presence(activity=discord.Streaming(name = name, url="https://www.twitch.tv/xchidz"))
100
101
@client.event
102
async def on_message(message):
103
104
if 'discord.gift/' in message.content:
105
code = re.search("discord.gift/(.*)", message.content).group(1)
106
headers = {'Authorization': token}
107
108
r = requests.post(
109
f'https://discordapp.com/api/v6/entitlements/gift-codes/{code}/redeem',
110
headers=headers,
111
).text
112
113
if 'Unknown Gift Code' in r:
114
print("failed to claim")
115
116
if 'Someone just dropped' in message.content:
117
if message.author.id == 346353957029019648:
118
try:
119
await message.channel.send('~grab')
120
except:
121
print("failed to claim")
122
123
await client.process_commands(message)
124
125
126
127
128
client.run(token,bot=False)
129
130
def click():
131
loop = asyncio.new_event_loop()
132
sb()
133
134
135
136
myButton = Button(root, text = "Confirm UserToken",command=threading.Thread(target=click).start())
137
myButton.grid(row=0, column=1)
138
I am struggling with incorporating threading into my tkinter program. This program is basically a discord bot that you are able to start, restart and other various things through a gui application. I realised that i need to incorporate threading into my tkinter gui in order to be able to use different buttons in the gui as the bot is active but the program keeps giving me the error in the title
Advertisement
Answer
I think your click
function should be like this:
JavaScript
1
4
1
def click():
2
loop = asyncio.new_event_loop()
3
sb(loop) # pass 'loop' as the argument
4