I'm trying to make a discord command where users can change what my bot is playing, but it changes for all servers and I don't want that. Is there a way to make it so that it only changes for the server that the user is sending the command from?
So far all I have is this
games={}
#bot.command(pass_context=True)
async def game(ctx, name):
server=ctx.message.server
games[server.name] = await bot.change_presence(game=discord.Game(name=name))
This is not possible as a Discord bot is only considered to have one websocket. You could make a loop and asyncio.sleep(time) to change the presence over time. Hope that helps!
Related
import discord
from discord.ext import commands
bot = discord.Bot(command_prefix='!')
#bot.event
#commands.has_permissions(administrator=False)
async def delmessage(message):
await message.delete()
As explained by stijndcl in comment, the best solution is to go directly in your server settings to allow only admins and moderators to use #everyone and #here.
If you still you want to use a bot, something can easily be done using the on_message handler and then checking the roles of the message author to delete or keep the message.
The problem with this method is that the filtering process is done after the message publication, so deleting an unauthorized ping will create ghost pings and therefore a poor experience for your server members (and again why bother when a setting exists for this exact purpose).
I'm currently programming a bot and my first goal is to make the bot welcome and say goodbye to members that join or leave, but the bot sends nothing, not even showing any error.
#client.event
async def on_member_join(member):
print(" System: A member has joined the server!")
def sprint(str):
for c in str + '\n':
sys.stdout.write(c)
sys.stdout.flush()
time.sleep(3./90)
sprint(" Bot: Oh hey, looks like "+member.name+" has joined..")
#send message to a specific channel
channel = client.get_channel(channel id from the welcome channel)
await channel.send("Hey! Welcome to the server, "+member.mention+"! I hope you read the #rules before doing anything, otherwise have fun and enjoy your stay!")
I did it last time before I recreated the script, but the on_member_join thing doesn't work, not even on_member_leave! (I'm doing the on_member_join first to check if it's working)
My alternate account rejoined my server, but the bot (except MEE6) didn't send anything.. Is there anything you guys can help me?
You'll need to enable the member intent by creating an instance of discord.Intents.default, setting Intents.members to True, and passing the instance into your commands.Bot or discord.Client constructor, like:
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(intents=intents)
You'll also need to enable the members intent in the Discord dev portal (https://discord.com/developers). Go to that url, click on your application, go to the Bot tab, scroll down to the 'privileged gateway intents' section, and enable the members intent.
Then, restart your bot, and member events should work.
(for more info, look at https://discordpy.readthedocs.io/en/latest/intents.html)
So basically what I am doing is trying to write a very basic kick and ban command to use for my discord bot. I've looked through many different tutorials and similar questions asked, but I simply cannot find a fix to this.
#bot.command()
#commands.has_permissions(kick_members=True)
async def kick(ctx, user: discord.Member, *, reason=None):
await ctx.kick(reason=reason)
await ctx.send(f"{user} has been kicked successfully")
When I have the bot up and running, everyone is able to kick everybody else regardless of whether they have permissions to kick members or not, even though I have specified it to check if the user is able to kick people. I want it so that if a user does not have permissions to kick members, they shouldn't be able to kick anyone. I am fairly new to coding, and any help is appreciated. If anyone would like to check for the rest of the code in my program, I am happy to post it, but for now I don't see a reason to have to.
await ctx.kick(reason=reason)
You're trying to kick the context. Kick the member instead:
await user.kick(reason=reason)
I'm looking into hosting an academic event in Discord. I need a bot that can check the presence of the enrolled in each activity, an activity being to watch seminars and alike through discord screensharing, so the adm team can have a secure track (if possible, with user email) of who can be awarded a certificate of participation. Would you know anything of this kind? Be it a ready-to-use bot or a source code.
The question is sadly wide, I'd like suggestions of any approaches that you could know.
(Edited)
It'll depend on exactly what you want, but here's something that should help if you're wanting to use discord.py.
import discord
client = discord.Client()
#client.event
async def on_ready():
vc = client.get_channel(id) #get the id of the voice channel
attend = vc.members
This will set attend to a list of members who were in the VC when you run the script. From there, you can do what you want with the list. For example, you could save a list of users' names to a file with this.
f = open('Attendees.txt', 'w')
f.write('\n'.join([user.name for user in attend]))
Not much to it really.
I just have a bot which has a chat filter function which i only want to run on my friends server. However i have the bot in multiple servers. What do i put before the code to make it only run in a certain server?
The most straightforward way would be to just put a conditional in your on_message definition that prevents it from taking action if the message wasn't from the given server.
async def on_message(message):
WHITELISTED_SERVER_ID = '01234567890123456789'
if message.channel.server.id == WHITELISTED_SERVER_ID:
// do whatever the bot does
You can adapt that to however your bot is designed. There are also other concerns (e.g. if the message is from a direct message, message.channel.server won't exist), but that's the gist of it.