I would like to make a specific command (!verify) in the chosen channel.
Q: What does it mean?
A: The answer is simple. I would like users to be able to write only this command to this channel and nothing else.
Library: Discord.js
You can do the following:
if (message.channel.id === 'id-of-allowed-channel') {
//rest of your code
}
This way, the command is only executed if the id of the channel where the message is sent in equals the id of the channel that you want the command to work in :)
But I need to be able to write only a certain command in this channel. I already know how to select a specific channel, it's just the command.
Related
So I'm coding a Discord bot for a friend and I need to see if a message was sent in a specific channel.
I tried a few things, asked a few people, and searched for an answer, but I couldn't find any.
This is about the closest I've gotten and I've tried changing a few objects:
if message.channelID == ('#858884357271322634'):
await message.channel.send ('I checked and verified the channel.')
Your check does not really makes sense, there is no such message.channelID.
Simply compare message.channel.id with the ID you want to and insert it correctly.
Simple example:
if message.channel.id == 858884357271322634:
await message.channel.send("I checked and verified the channel.")
I'm writing a discord bot using python to log options trade. What I'm looking to do with my bot is when a user type execute a command, !opentrade, the bot would private message the user with a series of questions. The bot would then capture the answer in a series of variables and use that to process the answer. Is this possible or does it have to be in the channel where the command is called. Additionally, is it by default multithread, meaning 2 or 3 people can call that command at the same time and it would fud up the answer
I have the following thus far and it isn't working:
async def opentrade(ctx):
def check(author):
def inner_check(message):
if message.author != author:
return False
try:
int(message.content)
return True
except ValueError:
return False
return inner_check
try:
await ctx.author.send('Enter the underlying: ')
underlying = await client.wait_for('message', check=check(ctx.author), timeout=30)
print (underlying)
except Exception as err:
await ctx.channel.send("Something went wrong: {}".format(err))
thanks
What I'm looking to do with my bot is when a user type execute a command, !opentrade, the bot would private message the user with a series of questions. The bot would then capture the answer in a series of variables and use that to process the answer. Is this possible or does it have to be in the channel where the command is called.
Possible. You need to put the whole logic into the coroutine that executes the command.
Additionally, is it by default multithread, meaning 2 or 3 people can call that command at the same time and it would fud up the answer
If you implement the checks properly it won't fud the answer. In your code you already implemented the logic that checks for the author so noone else can change it def check(author).
When executing the commands multiple times by different users it will also not fud the answer since the threads are independent.
You should extend this check so it checks for a message in a DM channel. The way your check is written now the caller can DM the bot or respond in a guild text channel.
I'm not sure what's saved in the ctx variable but I'm certain it has a message attribute.
Try await ctx.message.author.send(). If you are running into an error provide the error log.
I'm trying to basically do what the title says.
I've tried
let channel = message.channel.get(68352726916713XXXX)
message.channel.send(channel.topic)
and stuff like that, But nothing works.
Any suggestions or answers?
If you are trying to get a channel in the same guild as the message was sent in, use message.guild.channels.get. Otherwise, use client.channels.get.
let channel = message.guild.channels.get("68352726916713XXXX");
message.channel.send(channel.topic);
I'd like our Discord Bot to mention a specific channel, and let it be clickable. I understand mentioning a user you use the user ID. I do have the channel Id, just unsure how to implement it.
You just have to do the following:
message.channel.send('Please take a look at this Discord Server channel <#CHANNELID>')
or if you get the channel id from the bot
const channel = message.guild.channels.find(channel => channel.name === 'Name of the channel');
message.channel.send(`Please take a look at this Discord Server channel <#${channel.id}>`)
Then the channel is clickable like in this screenshot:
It is simple :^)
<#channel.id>
Channels on Discord have this special kinda syntax here:
<#channel id>
As commented by Elitezen here, running toString() on a Channel can do that mention for you. Then, just send that string yourself. It's much simpler than manually doing it.
Like this if you're answering a message:
message.channel.send(message.channel.toString());
Also, like answered by others in this question, you can do that yourself if you feel like it.
If you have a Channel object already, you can do something like this (imagine your channel is named myChannel - it doesn't have to be named that, though):
message.channel.send(`<#${message.channel.id}>`);
I promise, I've tried everything. I think I have the actually command down, but I can't figure out how to implement the name of the voice channel. Here's my code:
if (!message.mentions.users.first()) {
message.channel.send("You have to tag someone my dude.")
break;
}
var member = (message.mentions.users.first())
guild.member(member).setVoiceChannel(Rats)
message.channel.send(":right_facing_fist: " + member)
break;
It runs through just fine, but "Rats" (the voice channel) is undefined. Do I need a variable that has the voice channel name? Is there something else I'm doing wrong?
Thanks in advance :)
Seems like your code is fine to me, but the Assignment of Rats is wrong.
setVoiceChannel() method takes in an argument which is a channel with type voice. So all you have to do is just directly assign the voiceChannel object to Rats and it would work.
You can get the list of channels in a guild by message.guild.channels, which returns a Collection<Snowflake,Guildchannel>. From there, you can filter out all the non-VCs using filter . You can do channel.type === "voice" to check if a channel is a voice channel or not.