I followed discord tutorial to create a bot. https://discord.com/developers/docs/getting-started#running-your-app .
I can't get slash command to work. (/test and /channel)
From logs in glitch IDE, I get the following error.
403
Error: {"message":"Missing Access","code":50001}
at DiscordRequest (file:///app/utils.js:34:11)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async HasGuildCommand (file:///app/commands.js:16:17)
The line that cause error is line 16. shown below.
// Checks for a command
async function HasGuildCommand(appId, guildId, command) {
// API endpoint to get and post guild commands
const endpoint = `applications/${appId}/guilds/${guildId}/commands`;
try {
const res = await DiscordRequest(endpoint, { method: 'GET' });
const data = await res.json();
...
So this tells me that either appID or guildID are incorrect, but I don't think it is.
I followed every step correctly according to the tutorial to get all my credentials.
is it a common problem?
what is the best place to get help related to discord.js implementation problem?
reddit?
submit ticket to discord support? (seem sooooooooo over kill)
does discord have discord server to ask this question? I found discord-tester, discord-deverloper. To join, I need to takes quizzes or whatever. I will just do this last if reddit and submitting ticket doesn't work.
Thanks
discord developers > OAuth2 > General
check applications.commands
discord developers > OAuth2 > URL Generator
check applications.commands
discord
Related
What I'm trying to achieve is simple:
send a message like links: [link1](https://example.com/1), [link1](https://example.com/2) via a bot
get it displayed as "links: link1, link1"
In a ephemeral follow up, it works as expected:
const content = "links: [link1](https://example.com/1), [link1](https://example.com/2)"
await interaction.followUp({
ephemeral: true,
content,
})
But when I send this to a public channel like this:
await channel.send(content)
I'm getting it as plain text (links: [link1](https://example.com/1), [link1](https://example.com/2)) except the links are clickable.
Is it possible to get the same result as in an ephemeral message?
I've checked the permissions, there's only "embed" links (which sounds like "allow links in embeds", and not "allow links in messages) and it is enabled anyway on server for everyone, for the bot and in the channel. So what am I missing here?
PS Here they say that "it's only possible if the message was sent with webhook though", but I'm not quite sure what does this mean (can this be different for a public and an ephemeral message?)
You cannot use hyper links in normal messages sent by a bot. You need to use a Webhook. Considering you're using discord.js, see this guide on their documentation. When using something like that it will work as expected
const { WebhookClient } = require('discord.js');
const webhookClient = new WebhookClient({ url: "WEBHOOK_URL" });
webhookClient.send({
content: "[Hello world](https://github.com)",
username: "Webhook Username",
});
Otherwise you may use embeds and send one of these with your bot and the content you wish to have.
Right, so I've found a solution based on suggestion by Krypton. As an embed doesn't look nice and manual creation of a webhook is not an option for me, I've found that I can create a webhook on the go and use it.
After some testing, I've figured that such webhooks are also permanent (although they can be found in another part of settings than the manually created ones); they should be deleted as there's a limit of 15 webhooks – an attempt to create more fails (with DiscordAPIError[30007]: Maximum number of webhooks reached (15)).
Instead of doing
await channel.send(content)
I've put
// a guard, TypeScript requires us to be sure
if(channel instanceof TextChannel) {
const webhook = await channel.createWebhook({
// a message from a webhook has a different sender, here we set its name,
// for instance the same as the name of our bot (likewise, we can set an avatar)
name: "MyBot",
})
await webhook.send(content)
await webhook.delete()
}
This seems to be a minimal code change to get the links working.
I’m creating a discord bot using discord py and would like to have a kick command that dms the user a reason upon being kicked.
-kick #user reason
When I kick the user with a reason attached it doesn’t kick the user and I get an error in console saying can not find the user
Here is the code
#client.command(aliases=['Kick'])
#commands.has_permissions(administrator=True)
async def kick(ctx,member : discord.Member,*,reason= 'no reason'):
await ctx.send(f'{member.name} was kicked from the Server!\nand a Dm was sendet by me as a Information for him')
await asyncio.sleep(5)
await ctx.channel.purge(limit=2)
await member.send(f'**You was kicked from {ctx.guild.name}\nthe Stuff Team dont tell me the reason?**')
await member.kick(reason=reason)
print(f"{ctx.author} ----> just used {prefix}kick")
And yes I have tried Google, the discord py API guide with no luck
Can anyone help? Thanks
You can give a nice error message. It raises MemberNotFound.
Then you can make a local error handler.
#kick.error
async def kick_command_error(ctx, err):
if isinstance(err, commands.MemberNotFound):
await ctx.send('Hey! The member you gave is invalid or was not found. Please try again by `#`mentioning them or using the ID.')
I'm setting up a cron job to run a bot command that unlocks/locks a channel at a certain time every day. Trying to get the channel returns either undefined or null, depending on how I go about it.
The bot is added to the discord server and is online
require('dotenv').config();
const Discord = require("discord.js");
const client = new Discord.Client();
client.login(process.env.TOKEN);
const chan = client.channels.cache.get("858211703946084352");
console.log(chan);
const channel = client.channels.fetch("858211703946084352").then(res => {
console.log(res);
});
console.log(channel);
When I run it in the console I get
undefined
Promise { <pending> }
null
I have looked at many many examples and solutions, but none seem to resolve my issue
Edit:
bot has admin permissions.
I did the 'right click on channel and copy ID' technique, which matched the ID I got when I used dev tools to examine the element containing the channel name
There is a MEE6 bot in the server so I know bots can send messages
Edit2:
For fun and profit I deleted the app and remade it, same issue
I tried using a channel the MEE6 bot sends to, same issue
Try running this code in the ready event
client.on('ready', () => {
const chan = client.channels.cache.get("858211703946084352");
console.log(chan);
});
I'm trying to make a webhook so if anyone says 'ez' it deletes it and sends a message with the webhook with a random message. Originally what I was doing was
if "ez" in message.content:
webhook = await message.create_webhook(name=ctx.author.name)
await webhook.send(ezmessages[random.randint(0, len(ezmessages))-1], username=message.author.name, avatar_url=message.author.avatar_url)
await message.delete()
await webhook.delete()
but the problem is this gets rate limited if webhooks are created and deleted too quickly. So instead what I want to do is check if the bot already has a webhook for the text channel, and if there is one use that but if not use a different one. I thought this would work:
for webhook in message.channel.webhooks:
await webhook.send(ezmessages[random.randint(0, len(ezmessages))-1], username=message.author.name, avatar_url=message.author.avatar_url)
but I get the error
TypeError: 'method' object is not iterable
Even though it should return a list
Anyone know how to correctly iterate over this?
TextChannel.webhooks it's not an attribute, its a function and a coroutine, so you need to call it and await it
webhooks = await message.channel.webhooks()
for webhook in webhooks:
...
docs
I am trying to program a function that deletes the message with the command sent by the user.
E.g.:
User sends command /delmes
Bot sends a response to the command
Bot deletes the message sent by the user
Everything I was able to find until now (that would help me) was this Stack Overflow Thread: discord.py delete author message after executing command
But when I used the code, as described in the solutions, I only received AttributeError: 'Bot' object has no attribute 'delete_message'.
The discord.py API Reference (https://discordpy.readthedocs.io/en/latest/migrating.html#models-are-stateful / https://discordpy.readthedocs.io/en/latest/api.html?highlight=delete%20message#message) only revealed that some of the code had changed with newer versions.
So to speak client.delete_message would change to Message.delete(), if I interpreted it correctly!
After changing the code to what I thought it must be I received: NameError: name 'Message' is not defined
This is my code at the very last moment. (I am relatively new to discord.py and only used Python in school)
import discord
from discord.ext import commands
import random
import json
client = commands.Bot(command_prefix = '/', case_insensitive=True)
#client.command(pass_context=True)
async def delcommes(ctx):
await ctx.send("This is the response to the users command!")
await Message.delete(ctx.message, delay=3)
I couldn't understand your question very good but as far as I understand, when command executed, then after bot sends message, you want to delete the command message, in that case it's /delmes. You can use await ctx.message.delete().
#client.command(pass_context=True)
async def delcommes(ctx):
await ctx.send("This is the response to the users command!")
await ctx.message.delete()