Hey I am creating a discord bot using python I have put my first command it says pong but have edit that command and run the bot again and for checking I put the command ping the pong is repeated 2-3 times. This only my 1st command I have use I want to add more command then this issue I will face again plss help if someone is having to fix this thanks
import discord
from discord.ext import commands
bot = commands.Bot('!') # ! is Prefix
#bot.event
async def on_ready():
print("Bot is Online!")
#bot.command()
async def ping(ctx):
await ctx.send("pong")
#bot.command()
async def hi(ctx):
await ctx.send("hello")
bot.run(TOKEN)
Related
In Discord.py, we have created a command to banish a user. However, the result is output as Nameerror: name'app' is not definded. This is my code.
Do you have any problems with #app.command?
I use client run instead of app run.
#app.command(name="<<kick", pass_context= True)
#commands.has_permissions(administrator=True)
async def _kick(ctx, *, username: discord.Member, reason=None):
await user_name.kick(reason=reason)
await ctx.send(str(user_name) + '\n```User was kick!```')```
If you use client.run you also have to use #client.command(...).
Judging from your comments, you're using a discord.Client instead of a commands.Bot. If you want to use the commands module, you need to use commands.Bot instead.
I'm trying to send text from a wordlist line-by-line into a discord channel via a discord webhook. The script below only sends the last line in the wordlist for some reason.
from discord_webhook import DiscordWebhook
with open('wordlist.txt','r') as lines:
for line in lines:
webhook = DiscordWebhook(url='webhookurlhere', content=lines.readline()
response = webhook.execute()
from discord_webhook import DiscordWebhook
file = open("wordlist.txt", 'r')
lines = file.readlines()
for line in lines:
webhook= DiscordWebhook(url='myurl', content= line)
response = webhook.exectute()
file.close()
it appears you were missing a closing parenthesis on your discordwebhook call. i also structured the reading of the file a little differently, just easier for reading for me. see if this works for you.
So I'm making an afk command, and I want to store everything I type after !afk into the reason, instead of having to put "" around it. Is there any way I can do this? Thanks in advance :)
The text after the command is passed on as all variables in your program you can get all of those with *args and merge them back into a sentence with ' '.join(args).
Example code:
bot.command()
async def afk(ctx, *args):
reason = ' '.join(args)
ctx.send(f'{ctx.author.name} has gone afk with the following reason: "{reason}", bye')
Is there any possible way to log the name of the Lambda in CloudWatch ?
Ex:
START RequestId: 4b453a3-f239-461f-94ab-ebesdfsdb04de Version: $LATEST
The "RequestId" is already getting logged. Any property I can use to log the name of the lambda as well ?
I don't want an explicit console.log statement but a property/parameter which directly gives out my lambda's name along with START , END and INFO fields.
You should be using context property (function_name).
def lambda_handler(event, context):
print("lambda function: {}".format(context.function_name))
Please refer below link for more details.
You coud use environment variable AWS_LAMBDA_FUNCTION_NAME (see full list). If your Lambda are written on Python it could looks like this:
import os
def lambda_handler(event, context):
print("Running function '%s'" % os.environ.get('AWS_LAMBDA_FUNCTION_NAME', None))
could do this in nodejs
console.log(process.env.AWS_LAMBDA_FUNCTION_NAME)
so I am trying to delve into multiprocessing with python. I went to the python 3 website, to see some example code, and they have this:
from multiprocessing import Process
def f(name):
print('hello', name)
if __name__ == '__main__':
p = Process(target=f, args=('bob',))
p.start()
p.join()
I put it in my IDE and ran it, but nothing happens. If I run the debugger, it takes me to the process, and I see that everything happens, but just running it does nothing. Can someone help me?
Same code is working here :http://ideone.com/9kcQru
from multiprocessing import Process
def f(name):
print('hello', name)
if __name__ == '__main__':
p = Process(target=f, args=('bob',))
p.start()
p.join()
output : hello bob
There is something wrong with your environment