因此,我正在为我的dnd和lancer团队编写一个机器人,完全没有经验。我主要是将示例代码串在一起,然后使其工作。我目前正忙于获取反应角色的示例代码,以完整地看到它
here
我当前的代码是这样的
# This example requires the 'members' and 'message_content' privileged intents to function.
import discord
from discord.ext import commands
import random
import logging
description = '''Godawful bot programmed by my discord username
Primary use case is rolling dice and helping with scheduling for sessions. Also supposed to do reaction roles'''
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
bot = commands.Bot(command_prefix='p;', description=description, intents=intents)
handler = logging.FileHandler(filename='platform.log', encoding='utf-8', mode='w')
@bot.event
async def on_ready():
print(f'Logged in as {bot.user} (ID: {bot.user.id})')
print('------')
@bot.command()
async def roll(ctx, dice: str):
"""Rolls a dice in NdN format."""
try:
rolls, limit = map(int, dice.split('d'))
except Exception:
await ctx.send('ERROR:Syntax - Format has to be in NdN!')
return
result = ', '.join(str(random.randint(1, limit)) for r in range(rolls))
await ctx.send(result)
class MyClient(discord.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.role_message_id = '1249373090727858259' # ID of the message that can be reacted to to add/remove a role.
self.emoji_to_role = {
discord.PartialEmoji(name='ð´'): '1249516324603035689', # ID of the role associated with unicode emoji 'ð´'.
discord.PartialEmoji(name='ð¡'): '1249516335696973884', # ID of the role associated with unicode emoji 'ð¡'.
discord.PartialEmoji(name='green', id=0): 0, # ID of the role associated with a partial emoji's ID.
}
async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent):
"""Gives a role based on a reaction emoji."""
# Make sure that the message the user is reacting to is the one we care about.
if payload.message_id != self.role_message_id:
return
bot.run('bot key thing', log_handler=handler)
有人知道为什么反应角色不起作用吗?骰子滚轮工作正常
我尝试了发现的原始代码的各种变体
在这里
包括仅仅创建一个新应用程序并给予它所有正确的权限,然后尝试一下,它仍然无法工作